wined3d: Match device name string to windows one.
[wine/hacks.git] / dlls / wined3d / directx.c
blob6bad91e07e2750c601bb5a2ce59b179bf39c4961
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_draw_buffers", ARB_DRAW_BUFFERS, 0 },
67 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM, 0 },
68 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER, 0 },
69 {"GL_ARB_geometry_shader4", ARB_GEOMETRY_SHADER4, 0 },
70 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL, 0 },
71 {"GL_ARB_imaging", ARB_IMAGING, 0 },
72 {"GL_ARB_multisample", ARB_MULTISAMPLE, 0 }, /* needs GLX_ARB_MULTISAMPLE as well */
73 {"GL_ARB_multitexture", ARB_MULTITEXTURE, 0 },
74 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY, 0 },
75 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT, 0 },
76 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS, 0 },
77 {"GL_ARB_point_sprite", ARB_POINT_SPRITE, 0 },
78 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP, 0 },
79 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION, 0 },
80 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP, 0 },
81 {"GL_ARB_texture_env_add", ARB_TEXTURE_ENV_ADD, 0 },
82 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE, 0 },
83 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3, 0 },
84 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT, 0 },
85 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT, 0 },
86 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO, MAKEDWORD_VERSION(2, 0) },
87 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE, 0 },
88 {"GL_ARB_texture_rg", ARB_TEXTURE_RG, 0 },
89 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND, 0 },
90 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT, 0 },
91 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM, 0 },
92 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER, 0 },
93 {"GL_ARB_shader_objects", ARB_SHADER_OBJECTS, 0 },
94 {"GL_ARB_shader_texture_lod", ARB_SHADER_TEXTURE_LOD, 0 },
95 {"GL_ARB_half_float_vertex", ARB_HALF_FLOAT_VERTEX, 0 },
97 /* EXT */
98 {"GL_EXT_blend_color", EXT_BLEND_COLOR, 0 },
99 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX, 0 },
100 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE, 0 },
101 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE, 0 },
102 {"GL_EXT_fog_coord", EXT_FOG_COORD, 0 },
103 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT, 0 },
104 {"GL_EXT_framebuffer_multisample", EXT_FRAMEBUFFER_MULTISAMPLE, 0 },
105 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT, 0 },
106 {"GL_EXT_paletted_texture", EXT_PALETTED_TEXTURE, 0 },
107 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS, 0 },
108 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR, 0 },
109 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE, 0 },
110 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP, 0 },
111 {"GL_EXT_texture3D", EXT_TEXTURE3D, MAKEDWORD_VERSION(1, 2) },
112 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC, 0 },
113 {"GL_EXT_texture_compression_rgtc", EXT_TEXTURE_COMPRESSION_RGTC, 0 },
114 {"GL_EXT_texture_env_add", EXT_TEXTURE_ENV_ADD, 0 },
115 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE, 0 },
116 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3, 0 },
117 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB, 0 },
118 {"GL_EXT_texture_swizzle", EXT_TEXTURE_SWIZZLE, 0 },
119 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC, 0 },
120 {"GL_EXT_texture_lod", EXT_TEXTURE_LOD, 0 },
121 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS, 0 },
122 {"GL_EXT_vertex_array_bgra", EXT_VERTEX_ARRAY_BGRA, 0 },
123 {"GL_EXT_vertex_shader", EXT_VERTEX_SHADER, 0 },
124 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS, 0 },
126 /* NV */
127 {"GL_NV_half_float", NV_HALF_FLOAT, 0 },
128 {"GL_NV_fence", NV_FENCE, 0 },
129 {"GL_NV_fog_distance", NV_FOG_DISTANCE, 0 },
130 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM, 0 },
131 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2, 0 },
132 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS, 0 },
133 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2, 0 },
134 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION, 0 },
135 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4, 0 },
136 {"GL_NV_texture_shader", NV_TEXTURE_SHADER, 0 },
137 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2, 0 },
138 {"GL_NV_texture_shader3", NV_TEXTURE_SHADER3, 0 },
139 {"GL_NV_occlusion_query", NV_OCCLUSION_QUERY, 0 },
140 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM, 0 },
141 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1, 0 },
142 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2, 0 },
143 {"GL_NV_vertex_program2_option", NV_VERTEX_PROGRAM2_OPTION, 0 },
144 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3, 0 },
145 {"GL_NV_fragment_program_option", NV_FRAGMENT_PROGRAM_OPTION, 0 },
146 {"GL_NV_depth_clamp", NV_DEPTH_CLAMP, 0 },
147 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT, 0 },
149 /* SGI */
150 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP, 0 },
153 /**********************************************************
154 * Utility functions follow
155 **********************************************************/
157 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat, WINED3DSURFTYPE SurfaceType);
158 static const struct fragment_pipeline *select_fragment_implementation(struct WineD3DAdapter *adapter,
159 WINED3DDEVTYPE DeviceType);
160 static const shader_backend_t *select_shader_backend(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType);
161 static const struct blit_shader *select_blit_implementation(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType);
163 /* lookup tables */
164 const int minLookup[MAX_LOOKUPS] =
166 WINED3DTADDRESS_WRAP, /* WINELOOKUP_WARPPARAM */
169 const int maxLookup[MAX_LOOKUPS] =
171 WINED3DTADDRESS_MIRRORONCE, /* WINELOOKUP_WARPPARAM */
174 DWORD *stateLookup[MAX_LOOKUPS];
176 struct min_lookup minMipLookup[WINED3DTEXF_ANISOTROPIC + 1];
177 const struct min_lookup minMipLookup_noFilter[WINED3DTEXF_ANISOTROPIC + 1] =
179 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}},
180 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}},
181 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}},
182 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}},
185 GLenum magLookup[WINED3DTEXF_ANISOTROPIC + 1];
186 const GLenum magLookup_noFilter[WINED3DTEXF_ANISOTROPIC + 1] =
188 GL_NEAREST, GL_NEAREST, GL_NEAREST, GL_NEAREST
191 /* drawStridedSlow attributes */
192 glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT];
193 glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT];
194 glAttribFunc specular_func_3ubv;
195 glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT];
196 glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT];
197 glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT];
200 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created,
201 * i.e., there is no GL Context - Get a default rendering context to enable the
202 * function query some info from GL.
205 static int wined3d_fake_gl_context_ref = 0;
206 static BOOL wined3d_fake_gl_context_foreign;
207 static BOOL wined3d_fake_gl_context_available = FALSE;
208 static HDC wined3d_fake_gl_context_hdc = NULL;
209 static HWND wined3d_fake_gl_context_hwnd = NULL;
211 static CRITICAL_SECTION wined3d_fake_gl_context_cs;
212 static CRITICAL_SECTION_DEBUG wined3d_fake_gl_context_cs_debug =
214 0, 0, &wined3d_fake_gl_context_cs,
215 { &wined3d_fake_gl_context_cs_debug.ProcessLocksList,
216 &wined3d_fake_gl_context_cs_debug.ProcessLocksList },
217 0, 0, { (DWORD_PTR)(__FILE__ ": wined3d_fake_gl_context_cs") }
219 static CRITICAL_SECTION wined3d_fake_gl_context_cs = { &wined3d_fake_gl_context_cs_debug, -1, 0, 0, 0, 0 };
221 static void WineD3D_ReleaseFakeGLContext(void) {
222 HGLRC glCtx;
224 EnterCriticalSection(&wined3d_fake_gl_context_cs);
226 if(!wined3d_fake_gl_context_available) {
227 TRACE_(d3d_caps)("context not available\n");
228 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
229 return;
232 glCtx = pwglGetCurrentContext();
234 TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref);
235 if (0 == (--wined3d_fake_gl_context_ref) ) {
236 if(!wined3d_fake_gl_context_foreign && glCtx) {
237 TRACE_(d3d_caps)("destroying fake GL context\n");
238 pwglMakeCurrent(NULL, NULL);
239 pwglDeleteContext(glCtx);
241 if(wined3d_fake_gl_context_hdc)
242 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
243 wined3d_fake_gl_context_hdc = NULL; /* Make sure we don't think that it is still around */
244 if(wined3d_fake_gl_context_hwnd)
245 DestroyWindow(wined3d_fake_gl_context_hwnd);
246 wined3d_fake_gl_context_hwnd = NULL;
247 wined3d_fake_gl_context_available = FALSE;
249 assert(wined3d_fake_gl_context_ref >= 0);
251 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
254 static BOOL WineD3D_CreateFakeGLContext(void) {
255 HGLRC glCtx = NULL;
257 EnterCriticalSection(&wined3d_fake_gl_context_cs);
259 TRACE("getting context...\n");
260 if(wined3d_fake_gl_context_ref > 0) goto ret;
261 assert(0 == wined3d_fake_gl_context_ref);
263 wined3d_fake_gl_context_foreign = TRUE;
265 glCtx = pwglGetCurrentContext();
266 if (!glCtx) {
267 PIXELFORMATDESCRIPTOR pfd;
268 int iPixelFormat;
270 wined3d_fake_gl_context_foreign = FALSE;
272 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes */
273 wined3d_fake_gl_context_hwnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window", WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
274 if(!wined3d_fake_gl_context_hwnd) {
275 ERR("HWND creation failed!\n");
276 goto fail;
278 wined3d_fake_gl_context_hdc = GetDC(wined3d_fake_gl_context_hwnd);
279 if(!wined3d_fake_gl_context_hdc) {
280 ERR("GetDC failed!\n");
281 goto fail;
284 /* PixelFormat selection */
285 ZeroMemory(&pfd, sizeof(pfd));
286 pfd.nSize = sizeof(pfd);
287 pfd.nVersion = 1;
288 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;/*PFD_GENERIC_ACCELERATED*/
289 pfd.iPixelType = PFD_TYPE_RGBA;
290 pfd.cColorBits = 32;
291 pfd.iLayerType = PFD_MAIN_PLANE;
293 iPixelFormat = ChoosePixelFormat(wined3d_fake_gl_context_hdc, &pfd);
294 if(!iPixelFormat) {
295 /* If this happens something is very wrong as ChoosePixelFormat barely fails */
296 ERR("Can't find a suitable iPixelFormat\n");
297 goto fail;
299 DescribePixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, sizeof(pfd), &pfd);
300 SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd);
302 /* Create a GL context */
303 glCtx = pwglCreateContext(wined3d_fake_gl_context_hdc);
304 if (!glCtx) {
305 WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
306 goto fail;
309 /* Make it the current GL context */
310 if (!pwglMakeCurrent(wined3d_fake_gl_context_hdc, glCtx)) {
311 WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
312 goto fail;
316 ret:
317 TRACE("incrementing ref from %i\n", wined3d_fake_gl_context_ref);
318 wined3d_fake_gl_context_ref++;
319 wined3d_fake_gl_context_available = TRUE;
320 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
321 return TRUE;
322 fail:
323 if(wined3d_fake_gl_context_hdc)
324 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
325 wined3d_fake_gl_context_hdc = NULL;
326 if(wined3d_fake_gl_context_hwnd)
327 DestroyWindow(wined3d_fake_gl_context_hwnd);
328 wined3d_fake_gl_context_hwnd = NULL;
329 if(glCtx) pwglDeleteContext(glCtx);
330 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
331 return FALSE;
334 /* Adjust the amount of used texture memory */
335 long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram){
336 struct WineD3DAdapter *adapter = D3DDevice->adapter;
338 adapter->UsedTextureRam += glram;
339 TRACE("Adjusted gl ram by %ld to %d\n", glram, adapter->UsedTextureRam);
340 return adapter->UsedTextureRam;
343 /**********************************************************
344 * IUnknown parts follows
345 **********************************************************/
347 static HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
349 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
351 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
352 if (IsEqualGUID(riid, &IID_IUnknown)
353 || IsEqualGUID(riid, &IID_IWineD3DBase)
354 || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
355 IUnknown_AddRef(iface);
356 *ppobj = This;
357 return S_OK;
359 *ppobj = NULL;
360 return E_NOINTERFACE;
363 static ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
364 IWineD3DImpl *This = (IWineD3DImpl *)iface;
365 ULONG refCount = InterlockedIncrement(&This->ref);
367 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
368 return refCount;
371 static ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
372 IWineD3DImpl *This = (IWineD3DImpl *)iface;
373 ULONG ref;
374 TRACE("(%p) : Releasing from %d\n", This, This->ref);
375 ref = InterlockedDecrement(&This->ref);
376 if (ref == 0) {
377 unsigned int i;
379 for (i = 0; i < This->adapter_count; ++i)
381 HeapFree(GetProcessHeap(), 0, This->adapters[i].cfgs);
383 HeapFree(GetProcessHeap(), 0, This);
386 return ref;
389 /* Set the shader type for this device, depending on the given capabilities,
390 * the device type, and the user preferences in wined3d_settings */
392 static void select_shader_mode(const WineD3D_GL_Info *gl_info, WINED3DDEVTYPE DeviceType, int *ps_selected, int *vs_selected)
394 if (wined3d_settings.vs_mode == VS_NONE) {
395 *vs_selected = SHADER_NONE;
396 } else if (gl_info->supported[ARB_VERTEX_SHADER] && wined3d_settings.glslRequested) {
397 /* Geforce4 cards support GLSL but for vertex shaders only. Further its reported GLSL caps are
398 * wrong. This combined with the fact that glsl won't offer more features or performance, use ARB
399 * shaders only on this card. */
400 if(gl_info->vs_nv_version && gl_info->vs_nv_version < VS_VERSION_20)
401 *vs_selected = SHADER_ARB;
402 else
403 *vs_selected = SHADER_GLSL;
404 } else if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
405 *vs_selected = SHADER_ARB;
406 } else {
407 *vs_selected = SHADER_NONE;
410 if (wined3d_settings.ps_mode == PS_NONE) {
411 *ps_selected = SHADER_NONE;
412 } else if (gl_info->supported[ARB_FRAGMENT_SHADER] && wined3d_settings.glslRequested) {
413 *ps_selected = SHADER_GLSL;
414 } else if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
415 *ps_selected = SHADER_ARB;
416 } else if (gl_info->supported[ATI_FRAGMENT_SHADER]) {
417 *ps_selected = SHADER_ATI;
418 } else {
419 *ps_selected = SHADER_NONE;
423 /** Select the number of report maximum shader constants based on the selected shader modes */
424 static void select_shader_max_constants(
425 int ps_selected_mode,
426 int vs_selected_mode,
427 WineD3D_GL_Info *gl_info) {
429 switch (vs_selected_mode) {
430 case SHADER_GLSL:
431 gl_info->max_vshader_constantsF = gl_info->vs_glsl_constantsF;
432 break;
433 case SHADER_ARB:
434 gl_info->max_vshader_constantsF = gl_info->vs_arb_constantsF;
435 break;
436 default:
437 gl_info->max_vshader_constantsF = 0;
438 break;
441 switch (ps_selected_mode) {
442 case SHADER_GLSL:
443 gl_info->max_pshader_constantsF = gl_info->ps_glsl_constantsF;
444 break;
445 case SHADER_ARB:
446 gl_info->max_pshader_constantsF = gl_info->ps_arb_constantsF;
447 break;
448 default:
449 gl_info->max_pshader_constantsF = 0;
450 break;
454 /**********************************************************
455 * IWineD3D parts follows
456 **********************************************************/
458 /* GL locking is done by the caller */
459 static inline BOOL test_arb_vs_offset_limit(const WineD3D_GL_Info *gl_info)
461 GLuint prog;
462 BOOL ret = FALSE;
463 const char *testcode =
464 "!!ARBvp1.0\n"
465 "PARAM C[66] = { program.env[0..65] };\n"
466 "ADDRESS A0;"
467 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
468 "ARL A0.x, zero.x;\n"
469 "MOV result.position, C[A0.x + 65];\n"
470 "END\n";
472 while(glGetError());
473 GL_EXTCALL(glGenProgramsARB(1, &prog));
474 if(!prog) {
475 ERR("Failed to create an ARB offset limit test program\n");
477 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
478 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
479 strlen(testcode), testcode));
480 if(glGetError() != 0) {
481 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
482 TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
483 ret = TRUE;
484 } else TRACE("OpenGL implementation allows offsets > 63\n");
486 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
487 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
488 checkGLcall("ARB vp offset limit test cleanup\n");
490 return ret;
493 static DWORD ver_for_ext(GL_SupportedExt ext)
495 unsigned int i;
496 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
497 if(EXTENSION_MAP[i].extension == ext) {
498 return EXTENSION_MAP[i].version;
501 return 0;
504 static BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
505 const char *GL_Extensions = NULL;
506 const char *WGL_Extensions = NULL;
507 const char *gl_string = NULL;
508 const char *gl_string_cursor = NULL;
509 GLint gl_max;
510 GLfloat gl_floatv[2];
511 int major = 1, minor = 0;
512 BOOL return_value = TRUE;
513 unsigned i;
514 HDC hdc;
515 unsigned int vidmem=0;
517 TRACE_(d3d_caps)("(%p)\n", gl_info);
519 ENTER_GL();
521 gl_string = (const char *) glGetString(GL_RENDERER);
522 if (!gl_string) gl_string = "None";
523 strcpy(gl_info->gl_renderer, gl_string);
525 gl_string = (const char *) glGetString(GL_VENDOR);
526 TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
527 if (gl_string != NULL) {
528 /* Fill in the GL vendor */
529 if (strstr(gl_string, "NVIDIA")) {
530 gl_info->gl_vendor = VENDOR_NVIDIA;
531 } else if (strstr(gl_string, "ATI")) {
532 gl_info->gl_vendor = VENDOR_ATI;
533 } else if (strstr(gl_string, "Intel(R)") ||
534 strstr(gl_info->gl_renderer, "Intel(R)") ||
535 strstr(gl_string, "Intel Inc.")) {
536 gl_info->gl_vendor = VENDOR_INTEL;
537 } else if (strstr(gl_string, "Mesa")) {
538 gl_info->gl_vendor = VENDOR_MESA;
539 } else {
540 gl_info->gl_vendor = VENDOR_WINE;
542 } else {
543 gl_info->gl_vendor = VENDOR_WINE;
547 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
549 /* Parse the GL_VERSION field into major and minor information */
550 gl_string = (const char *) glGetString(GL_VERSION);
551 if (gl_string != NULL) {
553 /* First, parse the generic opengl version. This is supposed not to be convoluted with
554 * driver specific information
556 gl_string_cursor = gl_string;
557 major = atoi(gl_string_cursor);
558 if(major <= 0) {
559 ERR("Invalid opengl major version: %d\n", major);
561 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
562 ++gl_string_cursor;
564 if (*gl_string_cursor++ != '.') {
565 ERR_(d3d_caps)("Invalid opengl version string: %s\n", debugstr_a(gl_string));
567 minor = atoi(gl_string_cursor);
568 TRACE_(d3d_caps)("Found OpenGL version: %d.%d\n", major, minor);
569 gl_info->gl_version = MAKEDWORD_VERSION(major, minor);
571 /* Now parse the driver specific string which we'll report to the app */
572 switch (gl_info->gl_vendor) {
573 case VENDOR_NVIDIA:
574 gl_string_cursor = strstr(gl_string, "NVIDIA");
575 if (!gl_string_cursor) {
576 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
577 break;
580 gl_string_cursor = strstr(gl_string_cursor, " ");
581 if (!gl_string_cursor) {
582 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
583 break;
586 while (*gl_string_cursor == ' ') {
587 ++gl_string_cursor;
590 if (!*gl_string_cursor) {
591 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
592 break;
595 major = atoi(gl_string_cursor);
596 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
597 ++gl_string_cursor;
600 if (*gl_string_cursor++ != '.') {
601 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
602 break;
605 minor = atoi(gl_string_cursor);
606 minor = major*100+minor;
607 major = 10;
609 break;
611 case VENDOR_ATI:
612 major = minor = 0;
613 gl_string_cursor = strchr(gl_string, '-');
614 if (gl_string_cursor) {
615 int error = 0;
616 gl_string_cursor++;
618 /* Check if version number is of the form x.y.z */
619 if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
620 error = 1;
621 if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
622 error = 1;
623 if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
624 error = 1;
625 if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
626 error = 1;
628 /* Mark version number as malformed */
629 if (error)
630 gl_string_cursor = 0;
633 if (!gl_string_cursor)
634 WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
635 else {
636 major = *gl_string_cursor - '0';
637 minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
639 break;
641 case VENDOR_INTEL:
642 /* Apple and Mesa version strings look differently, but both provide intel drivers */
643 if(strstr(gl_string, "APPLE")) {
644 /* [0-9]+.[0-9]+ APPLE-[0-9]+.[0.9]+.[0.9]+
645 * We only need the first part, and use the APPLE as identification
646 * "1.2 APPLE-1.4.56"
648 gl_string_cursor = gl_string;
649 major = atoi(gl_string_cursor);
650 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
651 ++gl_string_cursor;
654 if (*gl_string_cursor++ != '.') {
655 ERR_(d3d_caps)("Invalid MacOS-Intel version string: %s\n", debugstr_a(gl_string));
656 break;
659 minor = atoi(gl_string_cursor);
660 break;
663 case VENDOR_MESA:
664 gl_string_cursor = strstr(gl_string, "Mesa");
665 gl_string_cursor = strstr(gl_string_cursor, " ");
666 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
667 if (*gl_string_cursor) {
668 char tmp[16];
669 int cursor = 0;
671 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
672 tmp[cursor++] = *gl_string_cursor;
673 ++gl_string_cursor;
675 tmp[cursor] = 0;
676 major = atoi(tmp);
678 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
679 ++gl_string_cursor;
681 cursor = 0;
682 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
683 tmp[cursor++] = *gl_string_cursor;
684 ++gl_string_cursor;
686 tmp[cursor] = 0;
687 minor = atoi(tmp);
689 break;
691 default:
692 major = 0;
693 minor = 9;
695 gl_info->driver_version = MAKEDWORD_VERSION(major, minor);
696 TRACE_(d3d_caps)("found driver version (%s)->%i.%i->(0x%08x)\n", debugstr_a(gl_string), major, minor, gl_info->driver_version);
697 /* Current Windows drivers have versions like 6.14.... (some older have an earlier version) */
698 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
699 } else {
700 FIXME("OpenGL driver did not return version information\n");
701 gl_info->driver_version = MAKEDWORD_VERSION(0, 0);
702 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
705 TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
708 * Initialize openGL extension related variables
709 * with Default values
711 memset(gl_info->supported, 0, sizeof(gl_info->supported));
712 gl_info->max_buffers = 1;
713 gl_info->max_textures = 1;
714 gl_info->max_texture_stages = 1;
715 gl_info->max_fragment_samplers = 1;
716 gl_info->max_vertex_samplers = 0;
717 gl_info->max_combined_samplers = gl_info->max_fragment_samplers + gl_info->max_vertex_samplers;
718 gl_info->max_sampler_stages = 1;
719 gl_info->ps_arb_version = PS_VERSION_NOT_SUPPORTED;
720 gl_info->ps_arb_max_temps = 0;
721 gl_info->ps_arb_max_instructions = 0;
722 gl_info->vs_arb_version = VS_VERSION_NOT_SUPPORTED;
723 gl_info->vs_arb_max_temps = 0;
724 gl_info->vs_arb_max_instructions = 0;
725 gl_info->vs_nv_version = VS_VERSION_NOT_SUPPORTED;
726 gl_info->vs_ati_version = VS_VERSION_NOT_SUPPORTED;
727 gl_info->vs_glsl_constantsF = 0;
728 gl_info->ps_glsl_constantsF = 0;
729 gl_info->vs_arb_constantsF = 0;
730 gl_info->ps_arb_constantsF = 0;
732 /* Retrieve opengl defaults */
733 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
734 gl_info->max_clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
735 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
737 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
738 gl_info->max_lights = gl_max;
739 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
741 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
742 gl_info->max_texture_size = gl_max;
743 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
745 glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, gl_floatv);
746 gl_info->max_pointsizemin = gl_floatv[0];
747 gl_info->max_pointsize = gl_floatv[1];
748 TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
750 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
751 GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
752 TRACE_(d3d_caps)("GL_Extensions reported:\n");
754 if (NULL == GL_Extensions) {
755 ERR(" GL_Extensions returns NULL\n");
756 } else {
757 while (*GL_Extensions != 0x00) {
758 const char *Start;
759 char ThisExtn[256];
760 size_t len;
762 while (isspace(*GL_Extensions)) GL_Extensions++;
763 Start = GL_Extensions;
764 while (!isspace(*GL_Extensions) && *GL_Extensions != 0x00) {
765 GL_Extensions++;
768 len = GL_Extensions - Start;
769 if (len == 0 || len >= sizeof(ThisExtn))
770 continue;
772 memcpy(ThisExtn, Start, len);
773 ThisExtn[len] = '\0';
774 TRACE_(d3d_caps)("- %s\n", ThisExtn);
776 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
777 if (!strcmp(ThisExtn, EXTENSION_MAP[i].extension_string)) {
778 TRACE_(d3d_caps)(" FOUND: %s support\n", EXTENSION_MAP[i].extension_string);
779 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
780 break;
785 LEAVE_GL();
787 /* Now work out what GL support this card really has */
788 #define USE_GL_FUNC(type, pfn, ext, replace) { \
789 DWORD ver = ver_for_ext(ext); \
790 if(gl_info->supported[ext]) gl_info->pfn = (type) pwglGetProcAddress(#pfn); \
791 else if(ver && ver <= gl_info->gl_version) gl_info->pfn = (type) pwglGetProcAddress(#replace); \
792 else gl_info->pfn = NULL; \
794 GL_EXT_FUNCS_GEN;
795 #undef USE_GL_FUNC
797 #define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type) pwglGetProcAddress(#pfn);
798 WGL_EXT_FUNCS_GEN;
799 #undef USE_GL_FUNC
801 ENTER_GL();
802 /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
803 * loading the functions, otherwise the code above will load the extension entry points instead of the
804 * core functions, which may not work
806 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
807 if (gl_info->supported[EXTENSION_MAP[i].extension] == FALSE &&
808 EXTENSION_MAP[i].version <= gl_info->gl_version && EXTENSION_MAP[i].version) {
809 TRACE_(d3d_caps)(" GL CORE: %s support\n", EXTENSION_MAP[i].extension_string);
810 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
814 if (gl_info->supported[APPLE_FENCE]) {
815 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
816 * The apple extension interacts with some other apple exts. Disable the NV
817 * extension if the apple one is support to prevent confusion in other parts
818 * of the code
820 gl_info->supported[NV_FENCE] = FALSE;
822 if (gl_info->supported[APPLE_FLOAT_PIXELS]) {
823 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
825 * The enums are the same:
826 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881A
827 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881B
828 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
829 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
830 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140B
832 if(!gl_info->supported[ARB_TEXTURE_FLOAT]) {
833 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels\n");
834 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
836 if(!gl_info->supported[ARB_HALF_FLOAT_PIXEL]) {
837 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels\n");
838 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
841 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) {
842 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
843 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
845 if (gl_info->supported[NV_TEXTURE_SHADER2]) {
846 if(gl_info->supported[NV_REGISTER_COMBINERS]) {
847 /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
848 * are supported. The nv extensions provide the same functionality as the
849 * ATI one, and a bit more(signed pixelformats)
851 gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
854 if (gl_info->supported[ARB_DRAW_BUFFERS]) {
855 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
856 gl_info->max_buffers = gl_max;
857 TRACE_(d3d_caps)("Max draw buffers: %u\n", gl_max);
859 if (gl_info->supported[ARB_MULTITEXTURE]) {
860 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
861 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
862 TRACE_(d3d_caps)("Max textures: %d\n", gl_info->max_textures);
864 if (gl_info->supported[NV_REGISTER_COMBINERS]) {
865 GLint tmp;
866 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &tmp);
867 gl_info->max_texture_stages = min(MAX_TEXTURES, tmp);
868 } else {
869 gl_info->max_texture_stages = min(MAX_TEXTURES, gl_max);
871 TRACE_(d3d_caps)("Max texture stages: %d\n", gl_info->max_texture_stages);
873 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
874 GLint tmp;
875 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
876 gl_info->max_fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
877 } else {
878 gl_info->max_fragment_samplers = max(gl_info->max_fragment_samplers, gl_max);
880 TRACE_(d3d_caps)("Max fragment samplers: %d\n", gl_info->max_fragment_samplers);
882 if (gl_info->supported[ARB_VERTEX_SHADER]) {
883 GLint tmp;
884 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
885 gl_info->max_vertex_samplers = tmp;
886 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
887 gl_info->max_combined_samplers = tmp;
889 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
890 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
891 * an issue because then the sampler setup only depends on the two shaders. If a pixel
892 * shader is used with fixed function vertex processing we're fine too because fixed function
893 * vertex processing doesn't use any samplers. If fixed function fragment processing is
894 * used we have to make sure that all vertex sampler setups are valid together with all
895 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
896 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
897 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
898 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
899 * a fixed function pipeline anymore.
901 * So this is just a check to check that our assumption holds true. If not, write a warning
902 * and reduce the number of vertex samplers or probably disable vertex texture fetch.
904 if(gl_info->max_vertex_samplers && gl_info->max_combined_samplers < 12 &&
905 MAX_TEXTURES + gl_info->max_vertex_samplers > gl_info->max_combined_samplers) {
906 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers\n",
907 gl_info->max_vertex_samplers, gl_info->max_combined_samplers);
908 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers\n");
909 if( gl_info->max_combined_samplers > MAX_TEXTURES )
910 gl_info->max_vertex_samplers =
911 gl_info->max_combined_samplers - MAX_TEXTURES;
912 else
913 gl_info->max_vertex_samplers = 0;
915 } else {
916 gl_info->max_combined_samplers = gl_info->max_fragment_samplers;
918 TRACE_(d3d_caps)("Max vertex samplers: %u\n", gl_info->max_vertex_samplers);
919 TRACE_(d3d_caps)("Max combined samplers: %u\n", gl_info->max_combined_samplers);
921 if (gl_info->supported[ARB_VERTEX_BLEND]) {
922 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
923 gl_info->max_blends = gl_max;
924 TRACE_(d3d_caps)("Max blends: %u\n", gl_info->max_blends);
926 if (gl_info->supported[EXT_TEXTURE3D]) {
927 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
928 gl_info->max_texture3d_size = gl_max;
929 TRACE_(d3d_caps)("Max texture3D size: %d\n", gl_info->max_texture3d_size);
931 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC]) {
932 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
933 gl_info->max_anisotropy = gl_max;
934 TRACE_(d3d_caps)("Max anisotropy: %d\n", gl_info->max_anisotropy);
936 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
937 gl_info->ps_arb_version = PS_VERSION_11;
938 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
939 gl_info->ps_arb_constantsF = gl_max;
940 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d\n", gl_info->ps_arb_constantsF);
941 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
942 gl_info->ps_arb_max_temps = gl_max;
943 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d\n", gl_info->ps_arb_max_temps);
944 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
945 gl_info->ps_arb_max_instructions = gl_max;
946 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d\n", gl_info->ps_arb_max_instructions);
948 if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
949 gl_info->vs_arb_version = VS_VERSION_11;
950 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
951 gl_info->vs_arb_constantsF = gl_max;
952 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d\n", gl_info->vs_arb_constantsF);
953 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
954 gl_info->vs_arb_max_temps = gl_max;
955 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d\n", gl_info->vs_arb_max_temps);
956 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
957 gl_info->vs_arb_max_instructions = gl_max;
958 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d\n", gl_info->vs_arb_max_instructions);
960 gl_info->arb_vs_offset_limit = test_arb_vs_offset_limit(gl_info);
962 if (gl_info->supported[ARB_VERTEX_SHADER]) {
963 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
964 gl_info->vs_glsl_constantsF = gl_max / 4;
965 TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u\n", gl_info->vs_glsl_constantsF);
967 if (gl_info->supported[ARB_FRAGMENT_SHADER]) {
968 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
969 gl_info->ps_glsl_constantsF = gl_max / 4;
970 TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u\n", gl_info->ps_glsl_constantsF);
971 glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
972 gl_info->max_glsl_varyings = gl_max;
973 TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings)\n", gl_max, gl_max / 4);
975 if (gl_info->supported[EXT_VERTEX_SHADER]) {
976 gl_info->vs_ati_version = VS_VERSION_11;
978 if (gl_info->supported[NV_VERTEX_PROGRAM3]) {
979 gl_info->vs_nv_version = VS_VERSION_30;
980 } else if (gl_info->supported[NV_VERTEX_PROGRAM2]) {
981 gl_info->vs_nv_version = VS_VERSION_20;
982 } else if (gl_info->supported[NV_VERTEX_PROGRAM1_1]) {
983 gl_info->vs_nv_version = VS_VERSION_11;
984 } else if (gl_info->supported[NV_VERTEX_PROGRAM]) {
985 gl_info->vs_nv_version = VS_VERSION_10;
987 if (gl_info->supported[NV_FRAGMENT_PROGRAM2]) {
988 gl_info->ps_nv_version = PS_VERSION_30;
989 } else if (gl_info->supported[NV_FRAGMENT_PROGRAM]) {
990 gl_info->ps_nv_version = PS_VERSION_20;
992 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT]) {
993 glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->max_shininess);
994 } else {
995 gl_info->max_shininess = 128.0;
997 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO]) {
998 /* If we have full NP2 texture support, disable GL_ARB_texture_rectangle because we will never use it.
999 * This saves a few redundant glDisable calls
1001 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
1003 if(gl_info->supported[ATI_FRAGMENT_SHADER]) {
1004 /* Disable NV_register_combiners and fragment shader if this is supported.
1005 * generally the NV extensions are preferred over the ATI ones, and this
1006 * extension is disabled if register_combiners and texture_shader2 are both
1007 * supported. So we reach this place only if we have incomplete NV dxlevel 8
1008 * fragment processing support
1010 gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
1011 gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
1012 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
1013 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
1014 gl_info->supported[NV_TEXTURE_SHADER3] = FALSE;
1016 if(gl_info->supported[NV_HALF_FLOAT]) {
1017 /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float */
1018 gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE;
1020 if(gl_info->supported[ARB_POINT_SPRITE]) {
1021 gl_info->max_point_sprite_units = gl_info->max_textures;
1022 } else {
1023 gl_info->max_point_sprite_units = 0;
1026 checkGLcall("extension detection\n");
1028 /* In some cases the number of texture stages can be larger than the number
1029 * of samplers. The GF4 for example can use only 2 samplers (no fragment
1030 * shaders), but 8 texture stages (register combiners). */
1031 gl_info->max_sampler_stages = max(gl_info->max_fragment_samplers, gl_info->max_texture_stages);
1033 /* We can only use ORM_FBO when the hardware supports it. */
1034 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && !gl_info->supported[EXT_FRAMEBUFFER_OBJECT]) {
1035 WARN_(d3d_caps)("GL_EXT_framebuffer_object not supported, falling back to PBuffer offscreen rendering mode.\n");
1036 wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
1039 /* MRTs are currently only supported when FBOs are used. */
1040 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) {
1041 gl_info->max_buffers = 1;
1044 /* Below is a list of Nvidia and ATI GPUs. Both vendors have dozens of different GPUs with roughly the same
1045 * features. In most cases GPUs from a certain family differ in clockspeeds, the amount of video memory and
1046 * in case of the latest videocards in the number of pixel/vertex pipelines.
1048 * A Direct3D device object contains the PCI id (vendor + device) of the videocard which is used for
1049 * rendering. Various games use this information to get a rough estimation of the features of the card
1050 * and some might use it for enabling 3d effects only on certain types of videocards. In some cases
1051 * games might even use it to work around bugs which happen on certain videocards/driver combinations.
1052 * The problem is that OpenGL only exposes a rendering string containing the name of the videocard and
1053 * not the PCI id.
1055 * Various games depend on the PCI id, so somehow we need to provide one. A simple option is to parse
1056 * the renderer string and translate this to the right PCI id. This is a lot of work because there are more
1057 * than 200 GPUs just for Nvidia. Various cards share the same renderer string, so the amount of code might
1058 * be 'small' but there are quite a number of exceptions which would make this a pain to maintain.
1059 * Another way would be to query the PCI id from the operating system (assuming this is the videocard which
1060 * is used for rendering which is not always the case). This would work but it is not very portable. Second
1061 * it would not work well in, let's say, a remote X situation in which the amount of 3d features which can be used
1062 * is limited.
1064 * As said most games only use the PCI id to get an indication of the capabilities of the card.
1065 * It doesn't really matter if the given id is the correct one if we return the id of a card with
1066 * similar 3d features.
1068 * The code below checks the OpenGL capabilities of a videocard and matches that to a certain level of
1069 * Direct3D functionality. Once a card passes the Direct3D9 check, we know that the card (in case of Nvidia)
1070 * is at least a GeforceFX. To give a better estimate we do a basic check on the renderer string but if that
1071 * won't pass we return a default card. This way is better than maintaining a full card database as even
1072 * without a full database we can return a card with similar features. Second the size of the database
1073 * can be made quite small because when you know what type of 3d functionality a card has, you know to which
1074 * GPU family the GPU must belong. Because of this you only have to check a small part of the renderer string
1075 * to distinguishes between different models from that family.
1077 * The code also selects a default amount of video memory which we will use for an estimation of the amount
1078 * of free texture memory. In case of real D3D the amount of texture memory includes video memory and system
1079 * memory (to be specific AGP memory or in case of PCIE TurboCache/HyperMemory). We don't know how much
1080 * system memory can be addressed by the system but we can make a reasonable estimation about the amount of
1081 * video memory. If the value is slightly wrong it doesn't matter as we didn't include AGP-like memory which
1082 * makes the amount of addressable memory higher and second OpenGL isn't that critical it moves to system
1083 * memory behind our backs if really needed.
1084 * Note that the amount of video memory can be overruled using a registry setting.
1086 switch (gl_info->gl_vendor) {
1087 case VENDOR_NVIDIA:
1088 /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1089 * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1091 if(WINE_D3D9_CAPABLE(gl_info) && (gl_info->vs_nv_version == VS_VERSION_30)) {
1092 /* Geforce 200 - highend */
1093 if(strstr(gl_info->gl_renderer, "GTX 280") ||
1094 strstr(gl_info->gl_renderer, "GTX 285") ||
1095 strstr(gl_info->gl_renderer, "GTX 295"))
1097 gl_info->gl_card = CARD_NVIDIA_GEFORCE_GTX280;
1098 vidmem = 1024;
1100 /* Geforce 200 - midend high */
1101 if(strstr(gl_info->gl_renderer, "GTX 275")) {
1102 gl_info->gl_card = CARD_NVIDIA_GEFORCE_GTX275;
1103 vidmem = 896;
1105 /* Geforce 200 - midend */
1106 if(strstr(gl_info->gl_renderer, "GTX 260")) {
1107 gl_info->gl_card = CARD_NVIDIA_GEFORCE_GTX260;
1108 vidmem = 1024;
1110 /* Geforce9 - highend / Geforce 200 - midend (GTS 150/250 are based on the same core) */
1111 else if(strstr(gl_info->gl_renderer, "9800") ||
1112 strstr(gl_info->gl_renderer, "GTS 150") ||
1113 strstr(gl_info->gl_renderer, "GTS 250"))
1115 gl_info->gl_card = CARD_NVIDIA_GEFORCE_9800GT;
1116 vidmem = 512;
1118 /* Geforce9 - midend */
1119 else if(strstr(gl_info->gl_renderer, "9600")) {
1120 gl_info->gl_card = CARD_NVIDIA_GEFORCE_9600GT;
1121 vidmem = 384; /* The 9600GSO has 384MB, the 9600GT has 512-1024MB */
1123 /* Geforce9 - midend low / Geforce 200 - low*/
1124 else if(strstr(gl_info->gl_renderer, "9500") ||
1125 strstr(gl_info->gl_renderer, "GT 120") ||
1126 strstr(gl_info->gl_renderer, "GT 130"))
1128 gl_info->gl_card = CARD_NVIDIA_GEFORCE_9500GT;
1129 vidmem = 256; /* The 9500GT has 256-1024MB */
1131 /* Geforce9 - lowend */
1132 else if(strstr(gl_info->gl_renderer, "9400")) {
1133 gl_info->gl_card = CARD_NVIDIA_GEFORCE_9400GT;
1134 vidmem = 256; /* The 9400GT has 256-1024MB */
1136 /* Geforce9 - lowend low */
1137 else if(strstr(gl_info->gl_renderer, "9100") ||
1138 strstr(gl_info->gl_renderer, "9200") ||
1139 strstr(gl_info->gl_renderer, "9300") ||
1140 strstr(gl_info->gl_renderer, "G 100"))
1142 gl_info->gl_card = CARD_NVIDIA_GEFORCE_9200;
1143 vidmem = 256; /* The 9100-9300 cards have 256MB */
1145 /* Geforce8 - highend */
1146 else if (strstr(gl_info->gl_renderer, "8800")) {
1147 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8800GTS;
1148 vidmem = 320; /* The 8800GTS uses 320MB, a 8800GTX can have 768MB */
1150 /* Geforce8 - midend mobile */
1151 else if(strstr(gl_info->gl_renderer, "8600 M")) {
1152 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600MGT;
1153 vidmem = 512;
1155 /* Geforce8 - midend */
1156 else if(strstr(gl_info->gl_renderer, "8600") ||
1157 strstr(gl_info->gl_renderer, "8700"))
1159 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600GT;
1160 vidmem = 256;
1162 /* Geforce8 - lowend */
1163 else if(strstr(gl_info->gl_renderer, "8300") ||
1164 strstr(gl_info->gl_renderer, "8400") ||
1165 strstr(gl_info->gl_renderer, "8500"))
1167 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8300GS;
1168 vidmem = 128; /* 128-256MB for a 8300, 256-512MB for a 8400 */
1170 /* Geforce7 - highend */
1171 else if(strstr(gl_info->gl_renderer, "7800") ||
1172 strstr(gl_info->gl_renderer, "7900") ||
1173 strstr(gl_info->gl_renderer, "7950") ||
1174 strstr(gl_info->gl_renderer, "Quadro FX 4") ||
1175 strstr(gl_info->gl_renderer, "Quadro FX 5"))
1177 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7800GT;
1178 vidmem = 256; /* A 7800GT uses 256MB while highend 7900 cards can use 512MB */
1180 /* Geforce7 midend */
1181 else if(strstr(gl_info->gl_renderer, "7600") ||
1182 strstr(gl_info->gl_renderer, "7700")) {
1183 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7600;
1184 vidmem = 256; /* The 7600 uses 256-512MB */
1185 /* Geforce7 lower medium */
1186 } else if(strstr(gl_info->gl_renderer, "7400")) {
1187 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7400;
1188 vidmem = 256; /* The 7400 uses 256-512MB */
1190 /* Geforce7 lowend */
1191 else if(strstr(gl_info->gl_renderer, "7300")) {
1192 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7300;
1193 vidmem = 256; /* Mac Pros with this card have 256 MB */
1195 /* Geforce6 highend */
1196 else if(strstr(gl_info->gl_renderer, "6800"))
1198 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6800;
1199 vidmem = 128; /* The 6800 uses 128-256MB, the 7600 uses 256-512MB */
1201 /* Geforce6 - midend */
1202 else if(strstr(gl_info->gl_renderer, "6600") ||
1203 strstr(gl_info->gl_renderer, "6610") ||
1204 strstr(gl_info->gl_renderer, "6700"))
1206 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6600GT;
1207 vidmem = 128; /* A 6600GT has 128-256MB */
1209 /* Geforce6/7 lowend */
1210 else {
1211 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
1212 vidmem = 64; /* */
1214 } else if(WINE_D3D9_CAPABLE(gl_info)) {
1215 /* GeforceFX - highend */
1216 if (strstr(gl_info->gl_renderer, "5800") ||
1217 strstr(gl_info->gl_renderer, "5900") ||
1218 strstr(gl_info->gl_renderer, "5950") ||
1219 strstr(gl_info->gl_renderer, "Quadro FX"))
1221 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5800;
1222 vidmem = 256; /* 5800-5900 cards use 256MB */
1224 /* GeforceFX - midend */
1225 else if(strstr(gl_info->gl_renderer, "5600") ||
1226 strstr(gl_info->gl_renderer, "5650") ||
1227 strstr(gl_info->gl_renderer, "5700") ||
1228 strstr(gl_info->gl_renderer, "5750"))
1230 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1231 vidmem = 128; /* A 5600 uses 128-256MB */
1233 /* GeforceFX - lowend */
1234 else {
1235 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1236 vidmem = 64; /* Normal FX5200 cards use 64-256MB; laptop (non-standard) can have less */
1238 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1239 if (strstr(gl_info->gl_renderer, "GeForce4 Ti") || strstr(gl_info->gl_renderer, "Quadro4")) {
1240 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1241 vidmem = 64; /* Geforce4 Ti cards have 64-128MB */
1243 else {
1244 gl_info->gl_card = CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1245 vidmem = 64; /* Geforce3 cards have 64-128MB */
1247 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1248 if (strstr(gl_info->gl_renderer, "GeForce4 MX")) {
1249 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1250 vidmem = 64; /* Most Geforce4MX GPUs have at least 64MB of memory, some early models had 32MB but most have 64MB or even 128MB */
1252 else if(strstr(gl_info->gl_renderer, "GeForce2 MX") || strstr(gl_info->gl_renderer, "Quadro2 MXR")) {
1253 gl_info->gl_card = CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1254 vidmem = 32; /* Geforce2MX GPUs have 32-64MB of video memory */
1256 else if(strstr(gl_info->gl_renderer, "GeForce2") || strstr(gl_info->gl_renderer, "Quadro2")) {
1257 gl_info->gl_card = CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1258 vidmem = 32; /* Geforce2 GPUs have 32-64MB of video memory */
1260 else {
1261 gl_info->gl_card = CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1262 vidmem = 32; /* Most Geforce1 cards have 32MB, there are also some rare 16 and 64MB (Dell) models */
1264 } else {
1265 if (strstr(gl_info->gl_renderer, "TNT2")) {
1266 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1267 vidmem = 32; /* Most TNT2 boards have 32MB, though there are 16MB boards too */
1269 else {
1270 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1271 vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
1274 break;
1275 case VENDOR_ATI:
1276 if(WINE_D3D9_CAPABLE(gl_info)) {
1277 /* Radeon R7xx HD4800 - highend */
1278 if (strstr(gl_info->gl_renderer, "HD 4800") ||
1279 strstr(gl_info->gl_renderer, "HD 4830") ||
1280 strstr(gl_info->gl_renderer, "HD 4850") ||
1281 strstr(gl_info->gl_renderer, "HD 4870") ||
1282 strstr(gl_info->gl_renderer, "HD 4890"))
1284 gl_info->gl_card = CARD_ATI_RADEON_HD4800;
1285 vidmem = 512; /* HD4800 cards use 512-1024MB */
1287 /* Radeon R6xx HD2900/HD3800 - highend */
1288 else if (strstr(gl_info->gl_renderer, "HD 2900") ||
1289 strstr(gl_info->gl_renderer, "HD 3870") ||
1290 strstr(gl_info->gl_renderer, "HD 3850"))
1292 gl_info->gl_card = CARD_ATI_RADEON_HD2900;
1293 vidmem = 512; /* HD2900/HD3800 uses 256-1024MB */
1295 /* Radeon R6xx HD2600/HD3600 - midend; HD3830 is China-only midend */
1296 else if (strstr(gl_info->gl_renderer, "HD 2600") ||
1297 strstr(gl_info->gl_renderer, "HD 3830") ||
1298 strstr(gl_info->gl_renderer, "HD 3690") ||
1299 strstr(gl_info->gl_renderer, "HD 3650"))
1301 gl_info->gl_card = CARD_ATI_RADEON_HD2600;
1302 vidmem = 256; /* HD2600/HD3600 uses 256-512MB */
1304 /* Radeon R6xx HD2300/HD2400/HD3400 - lowend */
1305 else if (strstr(gl_info->gl_renderer, "HD 2300") ||
1306 strstr(gl_info->gl_renderer, "HD 2400") ||
1307 strstr(gl_info->gl_renderer, "HD 3470") ||
1308 strstr(gl_info->gl_renderer, "HD 3450") ||
1309 strstr(gl_info->gl_renderer, "HD 3430"))
1311 gl_info->gl_card = CARD_ATI_RADEON_HD2300;
1312 vidmem = 128; /* HD2300 uses at least 128MB, HD2400 uses 256MB */
1314 /* Radeon R6xx/R7xx integrated */
1315 else if (strstr(gl_info->gl_renderer, "HD 3100") ||
1316 strstr(gl_info->gl_renderer, "HD 3200") ||
1317 strstr(gl_info->gl_renderer, "HD 3300"))
1319 gl_info->gl_card = CARD_ATI_RADEON_HD3200;
1320 vidmem = 128; /* 128MB */
1322 /* Radeon R5xx */
1323 else if (strstr(gl_info->gl_renderer, "X1600") ||
1324 strstr(gl_info->gl_renderer, "X1650") ||
1325 strstr(gl_info->gl_renderer, "X1800") ||
1326 strstr(gl_info->gl_renderer, "X1900") ||
1327 strstr(gl_info->gl_renderer, "X1950"))
1329 gl_info->gl_card = CARD_ATI_RADEON_X1600;
1330 vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
1332 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
1333 else if(strstr(gl_info->gl_renderer, "X700") ||
1334 strstr(gl_info->gl_renderer, "X800") ||
1335 strstr(gl_info->gl_renderer, "X850") ||
1336 strstr(gl_info->gl_renderer, "X1300") ||
1337 strstr(gl_info->gl_renderer, "X1400") ||
1338 strstr(gl_info->gl_renderer, "X1450") ||
1339 strstr(gl_info->gl_renderer, "X1550"))
1341 gl_info->gl_card = CARD_ATI_RADEON_X700;
1342 vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
1344 /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400MHz */
1345 else if(strstr(gl_info->gl_renderer, "Radeon Xpress"))
1347 gl_info->gl_card = CARD_ATI_RADEON_XPRESS_200M;
1348 vidmem = 64; /* Shared RAM, BIOS configurable, 64-256M */
1350 /* Radeon R3xx */
1351 else {
1352 gl_info->gl_card = CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
1353 vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
1355 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1356 gl_info->gl_card = CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
1357 vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
1358 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1359 gl_info->gl_card = CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
1360 vidmem = 32; /* There are models with up to 64MB */
1361 } else {
1362 gl_info->gl_card = CARD_ATI_RAGE_128PRO;
1363 vidmem = 16; /* There are 16-32MB models */
1365 break;
1366 case VENDOR_INTEL:
1367 if (strstr(gl_info->gl_renderer, "GMA 950") ||
1368 strstr(gl_info->gl_renderer, "945GM")) {
1369 /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */
1370 gl_info->gl_card = CARD_INTEL_I945GM;
1371 vidmem = 64;
1372 } else if (strstr(gl_info->gl_renderer, "915GM")) {
1373 gl_info->gl_card = CARD_INTEL_I915GM;
1374 } else if (strstr(gl_info->gl_renderer, "915G")) {
1375 gl_info->gl_card = CARD_INTEL_I915G;
1376 } else if (strstr(gl_info->gl_renderer, "865G")) {
1377 gl_info->gl_card = CARD_INTEL_I865G;
1378 } else if (strstr(gl_info->gl_renderer, "855G")) {
1379 gl_info->gl_card = CARD_INTEL_I855G;
1380 } else if (strstr(gl_info->gl_renderer, "830G")) {
1381 gl_info->gl_card = CARD_INTEL_I830G;
1382 } else {
1383 gl_info->gl_card = CARD_INTEL_I915G;
1385 break;
1386 case VENDOR_MESA:
1387 case VENDOR_WINE:
1388 default:
1389 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice
1390 * for Nvidia was because the hardware and drivers they make are of good quality. This makes
1391 * them a good generic choice.
1393 gl_info->gl_vendor = VENDOR_NVIDIA;
1394 if(WINE_D3D9_CAPABLE(gl_info))
1395 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1396 else if(WINE_D3D8_CAPABLE(gl_info))
1397 gl_info->gl_card = CARD_NVIDIA_GEFORCE3;
1398 else if(WINE_D3D7_CAPABLE(gl_info))
1399 gl_info->gl_card = CARD_NVIDIA_GEFORCE;
1400 else if(WINE_D3D6_CAPABLE(gl_info))
1401 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT;
1402 else
1403 gl_info->gl_card = CARD_NVIDIA_RIVA_128;
1405 TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card);
1407 /* If we have an estimate use it, else default to 64MB; */
1408 if(vidmem)
1409 gl_info->vidmem = vidmem*1024*1024; /* convert from MBs to bytes */
1410 else
1411 gl_info->vidmem = WINE_DEFAULT_VIDMEM;
1413 /* Load all the lookup tables */
1414 for (i = 0; i < MAX_LOOKUPS; i++) {
1415 stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
1418 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
1419 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
1420 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1421 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1422 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1423 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1424 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
1425 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
1426 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
1427 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
1429 magLookup[WINED3DTEXF_NONE - WINED3DTEXF_NONE] = GL_NEAREST;
1430 magLookup[WINED3DTEXF_POINT - WINED3DTEXF_NONE] = GL_NEAREST;
1431 magLookup[WINED3DTEXF_LINEAR - WINED3DTEXF_NONE] = GL_LINEAR;
1432 magLookup[WINED3DTEXF_ANISOTROPIC - WINED3DTEXF_NONE] =
1433 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR : GL_NEAREST;
1436 minMipLookup[WINED3DTEXF_NONE].mip[WINED3DTEXF_NONE] = GL_LINEAR;
1437 minMipLookup[WINED3DTEXF_NONE].mip[WINED3DTEXF_POINT] = GL_LINEAR;
1438 minMipLookup[WINED3DTEXF_NONE].mip[WINED3DTEXF_LINEAR] = GL_LINEAR;
1439 minMipLookup[WINED3DTEXF_POINT].mip[WINED3DTEXF_NONE] = GL_NEAREST;
1440 minMipLookup[WINED3DTEXF_POINT].mip[WINED3DTEXF_POINT] = GL_NEAREST_MIPMAP_NEAREST;
1441 minMipLookup[WINED3DTEXF_POINT].mip[WINED3DTEXF_LINEAR] = GL_NEAREST_MIPMAP_LINEAR;
1442 minMipLookup[WINED3DTEXF_LINEAR].mip[WINED3DTEXF_NONE] = GL_LINEAR;
1443 minMipLookup[WINED3DTEXF_LINEAR].mip[WINED3DTEXF_POINT] = GL_LINEAR_MIPMAP_NEAREST;
1444 minMipLookup[WINED3DTEXF_LINEAR].mip[WINED3DTEXF_LINEAR] = GL_LINEAR_MIPMAP_LINEAR;
1445 minMipLookup[WINED3DTEXF_ANISOTROPIC].mip[WINED3DTEXF_NONE]
1446 = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1447 minMipLookup[WINED3DTEXF_ANISOTROPIC].mip[WINED3DTEXF_POINT]
1448 = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR;
1449 minMipLookup[WINED3DTEXF_ANISOTROPIC].mip[WINED3DTEXF_LINEAR]
1450 = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1452 /* TODO: config lookups */
1454 /* Make sure there's an active HDC else the WGL extensions will fail */
1455 hdc = pwglGetCurrentDC();
1456 if (hdc) {
1457 /* Not all GL drivers might offer WGL extensions e.g. VirtualBox */
1458 if(GL_EXTCALL(wglGetExtensionsStringARB))
1459 WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc));
1461 if (NULL == WGL_Extensions) {
1462 ERR(" WGL_Extensions returns NULL\n");
1463 } else {
1464 TRACE_(d3d_caps)("WGL_Extensions reported:\n");
1465 while (*WGL_Extensions != 0x00) {
1466 const char *Start;
1467 char ThisExtn[256];
1468 size_t len;
1470 while (isspace(*WGL_Extensions)) WGL_Extensions++;
1471 Start = WGL_Extensions;
1472 while (!isspace(*WGL_Extensions) && *WGL_Extensions != 0x00) {
1473 WGL_Extensions++;
1476 len = WGL_Extensions - Start;
1477 if (len == 0 || len >= sizeof(ThisExtn))
1478 continue;
1480 memcpy(ThisExtn, Start, len);
1481 ThisExtn[len] = '\0';
1482 TRACE_(d3d_caps)("- %s\n", ThisExtn);
1484 if (!strcmp(ThisExtn, "WGL_ARB_pbuffer")) {
1485 gl_info->supported[WGL_ARB_PBUFFER] = TRUE;
1486 TRACE_(d3d_caps)("FOUND: WGL_ARB_pbuffer support\n");
1488 if (!strcmp(ThisExtn, "WGL_ARB_pixel_format")) {
1489 gl_info->supported[WGL_ARB_PIXEL_FORMAT] = TRUE;
1490 TRACE_(d3d_caps)("FOUND: WGL_ARB_pixel_format support\n");
1492 if (!strcmp(ThisExtn, "WGL_WINE_pixel_format_passthrough")) {
1493 gl_info->supported[WGL_WINE_PIXEL_FORMAT_PASSTHROUGH] = TRUE;
1494 TRACE_(d3d_caps)("FOUND: WGL_WINE_pixel_format_passthrough support\n");
1499 LEAVE_GL();
1501 return return_value;
1504 /**********************************************************
1505 * IWineD3D implementation follows
1506 **********************************************************/
1508 static UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
1509 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1511 TRACE_(d3d_caps)("(%p): Reporting %u adapters\n", This, This->adapter_count);
1513 return This->adapter_count;
1516 static HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
1517 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1518 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
1519 return WINED3D_OK;
1522 static HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
1523 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1525 TRACE_(d3d_caps)("(%p)->(%d)\n", This, Adapter);
1527 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
1528 return NULL;
1531 return MonitorFromPoint(This->adapters[Adapter].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
1534 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
1535 of the same bpp but different resolutions */
1537 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1538 static UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
1539 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1540 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
1542 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1543 return 0;
1546 /* TODO: Store modes per adapter and read it from the adapter structure */
1547 if (Adapter == 0) { /* Display */
1548 int i = 0;
1549 int j = 0;
1551 if (!DEBUG_SINGLE_MODE) {
1552 DEVMODEW DevModeW;
1554 ZeroMemory(&DevModeW, sizeof(DevModeW));
1555 DevModeW.dmSize = sizeof(DevModeW);
1556 while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
1557 j++;
1558 switch (Format)
1560 case WINED3DFMT_UNKNOWN:
1561 /* This is for D3D8, do not enumerate P8 here */
1562 if (DevModeW.dmBitsPerPel == 32 ||
1563 DevModeW.dmBitsPerPel == 16) i++;
1564 break;
1565 case WINED3DFMT_X8R8G8B8:
1566 if (DevModeW.dmBitsPerPel == 32) i++;
1567 break;
1568 case WINED3DFMT_R5G6B5:
1569 if (DevModeW.dmBitsPerPel == 16) i++;
1570 break;
1571 case WINED3DFMT_P8:
1572 if (DevModeW.dmBitsPerPel == 8) i++;
1573 break;
1574 default:
1575 /* Skip other modes as they do not match the requested format */
1576 break;
1579 } else {
1580 i = 1;
1581 j = 1;
1584 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
1585 return i;
1586 } else {
1587 FIXME_(d3d_caps)("Adapter not primary display\n");
1589 return 0;
1592 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1593 static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, WINED3DDISPLAYMODE* pMode) {
1594 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1595 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
1597 /* Validate the parameters as much as possible */
1598 if (NULL == pMode ||
1599 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
1600 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
1601 return WINED3DERR_INVALIDCALL;
1604 /* TODO: Store modes per adapter and read it from the adapter structure */
1605 if (Adapter == 0 && !DEBUG_SINGLE_MODE) { /* Display */
1606 DEVMODEW DevModeW;
1607 int ModeIdx = 0;
1608 UINT i = 0;
1609 int j = 0;
1611 ZeroMemory(&DevModeW, sizeof(DevModeW));
1612 DevModeW.dmSize = sizeof(DevModeW);
1614 /* If we are filtering to a specific format (D3D9), then need to skip
1615 all unrelated modes, but if mode is irrelevant (D3D8), then we can
1616 just count through the ones with valid bit depths */
1617 while ((i<=Mode) && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0)) {
1618 switch (Format)
1620 case WINED3DFMT_UNKNOWN:
1621 /* This is D3D8. Do not enumerate P8 here */
1622 if (DevModeW.dmBitsPerPel == 32 ||
1623 DevModeW.dmBitsPerPel == 16) i++;
1624 break;
1625 case WINED3DFMT_X8R8G8B8:
1626 if (DevModeW.dmBitsPerPel == 32) i++;
1627 break;
1628 case WINED3DFMT_R5G6B5:
1629 if (DevModeW.dmBitsPerPel == 16) i++;
1630 break;
1631 case WINED3DFMT_P8:
1632 if (DevModeW.dmBitsPerPel == 8) i++;
1633 break;
1634 default:
1635 /* Modes that don't match what we support can get an early-out */
1636 TRACE_(d3d_caps)("Searching for %s, returning D3DERR_INVALIDCALL\n", debug_d3dformat(Format));
1637 return WINED3DERR_INVALIDCALL;
1641 if (i == 0) {
1642 TRACE_(d3d_caps)("No modes found for format (%x - %s)\n", Format, debug_d3dformat(Format));
1643 return WINED3DERR_INVALIDCALL;
1645 ModeIdx = j - 1;
1647 /* Now get the display mode via the calculated index */
1648 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0)) {
1649 pMode->Width = DevModeW.dmPelsWidth;
1650 pMode->Height = DevModeW.dmPelsHeight;
1651 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1652 if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
1653 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1655 if (Format == WINED3DFMT_UNKNOWN) {
1656 pMode->Format = pixelformat_for_depth(DevModeW.dmBitsPerPel);
1657 } else {
1658 pMode->Format = Format;
1660 } else {
1661 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
1662 return WINED3DERR_INVALIDCALL;
1665 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
1666 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format),
1667 DevModeW.dmBitsPerPel);
1669 } else if (DEBUG_SINGLE_MODE) {
1670 /* Return one setting of the format requested */
1671 if (Mode > 0) return WINED3DERR_INVALIDCALL;
1672 pMode->Width = 800;
1673 pMode->Height = 600;
1674 pMode->RefreshRate = 60;
1675 pMode->Format = (Format == WINED3DFMT_UNKNOWN) ? WINED3DFMT_X8R8G8B8 : Format;
1676 } else {
1677 FIXME_(d3d_caps)("Adapter not primary display\n");
1680 return WINED3D_OK;
1683 static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, WINED3DDISPLAYMODE* pMode) {
1684 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1685 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
1687 if (NULL == pMode ||
1688 Adapter >= IWineD3D_GetAdapterCount(iface)) {
1689 return WINED3DERR_INVALIDCALL;
1692 if (Adapter == 0) { /* Display */
1693 int bpp = 0;
1694 DEVMODEW DevModeW;
1696 ZeroMemory(&DevModeW, sizeof(DevModeW));
1697 DevModeW.dmSize = sizeof(DevModeW);
1699 EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &DevModeW, 0);
1700 pMode->Width = DevModeW.dmPelsWidth;
1701 pMode->Height = DevModeW.dmPelsHeight;
1702 bpp = DevModeW.dmBitsPerPel;
1703 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1704 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
1706 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1709 pMode->Format = pixelformat_for_depth(bpp);
1710 } else {
1711 FIXME_(d3d_caps)("Adapter not primary display\n");
1714 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
1715 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
1716 return WINED3D_OK;
1719 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
1720 and fields being inserted in the middle, a new structure is used in place */
1721 static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
1722 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
1723 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1725 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %x, pId=%p)\n", This, Adapter, Flags, pIdentifier);
1727 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1728 return WINED3DERR_INVALIDCALL;
1731 /* Return the information requested */
1732 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
1733 strcpy(pIdentifier->Driver, This->adapters[Adapter].driver);
1734 if(This->adapters[Adapter].gl_info.driver_description)
1735 strcpy(pIdentifier->Description, This->adapters[Adapter].gl_info.driver_description);
1736 else /* Copy default description "Direct3D HAL" */
1737 strcpy(pIdentifier->Description, This->adapters[Adapter].description);
1739 /* Note dx8 doesn't supply a DeviceName */
1740 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY1"); /* FIXME: May depend on desktop? */
1741 pIdentifier->DriverVersion->u.HighPart = This->adapters[Adapter].gl_info.driver_version_hipart;
1742 pIdentifier->DriverVersion->u.LowPart = This->adapters[Adapter].gl_info.driver_version;
1743 *(pIdentifier->VendorId) = This->adapters[Adapter].gl_info.gl_vendor;
1744 *(pIdentifier->DeviceId) = This->adapters[Adapter].gl_info.gl_card;
1745 *(pIdentifier->SubSysId) = 0;
1746 *(pIdentifier->Revision) = 0;
1747 *pIdentifier->DeviceIdentifier = IID_D3DDEVICE_D3DUID;
1749 if(wined3d_settings.pci_device_id != PCI_DEVICE_NONE)
1751 TRACE_(d3d_caps)("Overriding pci device id with: %x\n", wined3d_settings.pci_device_id);
1752 *(pIdentifier->DeviceId) = wined3d_settings.pci_device_id;
1755 if(wined3d_settings.pci_vendor_id != PCI_VENDOR_NONE)
1757 TRACE_(d3d_caps)("Overriding pci vendor id with: %x\n", wined3d_settings.pci_vendor_id);
1758 *(pIdentifier->VendorId) = wined3d_settings.pci_vendor_id;
1761 if (Flags & WINED3DENUM_NO_WHQL_LEVEL) {
1762 *(pIdentifier->WHQLLevel) = 0;
1763 } else {
1764 *(pIdentifier->WHQLLevel) = 1;
1767 return WINED3D_OK;
1770 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const WineD3D_GL_Info *gl_info,
1771 const WineD3D_PixelFormat *cfg, const struct GlPixelFormatDesc *format_desc)
1773 short redSize, greenSize, blueSize, alphaSize, colorBits;
1775 if(!cfg)
1776 return FALSE;
1778 if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */
1779 if (!getColorBits(format_desc, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
1781 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(format_desc->format));
1782 return FALSE;
1785 if(cfg->redSize < redSize)
1786 return FALSE;
1788 if(cfg->greenSize < greenSize)
1789 return FALSE;
1791 if(cfg->blueSize < blueSize)
1792 return FALSE;
1794 if(cfg->alphaSize < alphaSize)
1795 return FALSE;
1797 return TRUE;
1798 } else if(cfg->iPixelType == WGL_TYPE_RGBA_FLOAT_ARB) { /* Float RGBA formats; TODO: WGL_NV_float_buffer */
1799 if (format_desc->format == WINED3DFMT_R16_FLOAT)
1800 return (cfg->redSize == 16 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1801 if (format_desc->format == WINED3DFMT_R16G16_FLOAT)
1802 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1803 if (format_desc->format == WINED3DFMT_R16G16B16A16_FLOAT)
1804 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 16 && cfg->alphaSize == 16);
1805 if (format_desc->format == WINED3DFMT_R32_FLOAT)
1806 return (cfg->redSize == 32 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1807 if (format_desc->format == WINED3DFMT_R32G32_FLOAT)
1808 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1809 if (format_desc->format == WINED3DFMT_R32G32B32A32_FLOAT)
1810 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 32 && cfg->alphaSize == 32);
1811 } else {
1812 /* Probably a color index mode */
1813 return FALSE;
1816 return FALSE;
1819 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const WineD3D_GL_Info *gl_info,
1820 const WineD3D_PixelFormat *cfg, const struct GlPixelFormatDesc *format_desc)
1822 short depthSize, stencilSize;
1823 BOOL lockable = FALSE;
1825 if(!cfg)
1826 return FALSE;
1828 if (!getDepthStencilBits(format_desc, &depthSize, &stencilSize))
1830 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(format_desc->format));
1831 return FALSE;
1834 if ((format_desc->format == WINED3DFMT_D16_LOCKABLE) || (format_desc->format == WINED3DFMT_D32F_LOCKABLE))
1835 lockable = TRUE;
1837 /* On some modern cards like the Geforce8/9 GLX doesn't offer some dephthstencil formats which D3D9 reports.
1838 * We can safely report 'compatible' formats (e.g. D24 can be used for D16) as long as we aren't dealing with
1839 * a lockable format. This also helps D3D <= 7 as they expect D16 which isn't offered without this on Geforce8 cards. */
1840 if(!(cfg->depthSize == depthSize || (!lockable && cfg->depthSize > depthSize)))
1841 return FALSE;
1843 /* Some cards like Intel i915 ones only offer D24S8 but lots of games also need a format without stencil, so
1844 * allow more stencil bits than requested. */
1845 if(cfg->stencilSize < stencilSize)
1846 return FALSE;
1848 return TRUE;
1851 static HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1852 WINED3DFORMAT AdapterFormat,
1853 WINED3DFORMAT RenderTargetFormat,
1854 WINED3DFORMAT DepthStencilFormat) {
1855 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1856 int nCfgs;
1857 const WineD3D_PixelFormat *cfgs;
1858 const struct WineD3DAdapter *adapter;
1859 const struct GlPixelFormatDesc *rt_format_desc;
1860 const struct GlPixelFormatDesc *ds_format_desc;
1861 int it;
1863 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
1864 This, Adapter,
1865 DeviceType, debug_d3ddevicetype(DeviceType),
1866 AdapterFormat, debug_d3dformat(AdapterFormat),
1867 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
1868 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
1870 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1871 TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning WINED3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
1872 return WINED3DERR_INVALIDCALL;
1875 adapter = &This->adapters[Adapter];
1876 rt_format_desc = getFormatDescEntry(RenderTargetFormat, &adapter->gl_info);
1877 ds_format_desc = getFormatDescEntry(DepthStencilFormat, &adapter->gl_info);
1878 cfgs = adapter->cfgs;
1879 nCfgs = adapter->nCfgs;
1880 for (it = 0; it < nCfgs; ++it) {
1881 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, &cfgs[it], rt_format_desc))
1883 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[it], ds_format_desc))
1885 TRACE_(d3d_caps)("(%p) : Formats matched\n", This);
1886 return WINED3D_OK;
1890 WARN_(d3d_caps)("unsupported format pair: %s and %s\n", debug_d3dformat(RenderTargetFormat), debug_d3dformat(DepthStencilFormat));
1892 return WINED3DERR_NOTAVAILABLE;
1895 static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1896 WINED3DFORMAT SurfaceFormat,
1897 BOOL Windowed, WINED3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
1899 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1900 const struct GlPixelFormatDesc *glDesc;
1901 const struct WineD3DAdapter *adapter;
1903 TRACE_(d3d_caps)("(%p)-> (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
1904 This,
1905 Adapter,
1906 DeviceType, debug_d3ddevicetype(DeviceType),
1907 SurfaceFormat, debug_d3dformat(SurfaceFormat),
1908 Windowed,
1909 MultiSampleType,
1910 pQualityLevels);
1912 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1913 return WINED3DERR_INVALIDCALL;
1916 /* TODO: handle Windowed, add more quality levels */
1918 if (WINED3DMULTISAMPLE_NONE == MultiSampleType) return WINED3D_OK;
1920 /* By default multisampling is disabled right now as it causes issues
1921 * on some Nvidia driver versions and it doesn't work well in combination
1922 * with FBOs yet. */
1923 if(!wined3d_settings.allow_multisampling)
1924 return WINED3DERR_NOTAVAILABLE;
1926 adapter = &This->adapters[Adapter];
1927 glDesc = getFormatDescEntry(SurfaceFormat, &adapter->gl_info);
1928 if (!glDesc) return WINED3DERR_INVALIDCALL;
1930 if(glDesc->Flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)) {
1931 int i, nCfgs;
1932 const WineD3D_PixelFormat *cfgs;
1934 cfgs = adapter->cfgs;
1935 nCfgs = adapter->nCfgs;
1936 for(i=0; i<nCfgs; i++) {
1937 if(cfgs[i].numSamples != MultiSampleType)
1938 continue;
1940 if (!IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[i], glDesc))
1941 continue;
1943 TRACE("Found iPixelFormat=%d to support MultiSampleType=%d for format %s\n", cfgs[i].iPixelFormat, MultiSampleType, debug_d3dformat(SurfaceFormat));
1945 if(pQualityLevels)
1946 *pQualityLevels = 1; /* Guess at a value! */
1947 return WINED3D_OK;
1950 else if(glDesc->Flags & WINED3DFMT_FLAG_RENDERTARGET) {
1951 short redSize, greenSize, blueSize, alphaSize, colorBits;
1952 int i, nCfgs;
1953 const WineD3D_PixelFormat *cfgs;
1955 if (!getColorBits(glDesc, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
1957 ERR("Unable to color bits for format %#x, can't check multisampling capability!\n", SurfaceFormat);
1958 return WINED3DERR_NOTAVAILABLE;
1961 cfgs = adapter->cfgs;
1962 nCfgs = adapter->nCfgs;
1963 for(i=0; i<nCfgs; i++) {
1964 if(cfgs[i].numSamples != MultiSampleType)
1965 continue;
1966 if(cfgs[i].redSize != redSize)
1967 continue;
1968 if(cfgs[i].greenSize != greenSize)
1969 continue;
1970 if(cfgs[i].blueSize != blueSize)
1971 continue;
1972 if(cfgs[i].alphaSize != alphaSize)
1973 continue;
1975 TRACE("Found iPixelFormat=%d to support MultiSampleType=%d for format %s\n", cfgs[i].iPixelFormat, MultiSampleType, debug_d3dformat(SurfaceFormat));
1977 if(pQualityLevels)
1978 *pQualityLevels = 1; /* Guess at a value! */
1979 return WINED3D_OK;
1982 return WINED3DERR_NOTAVAILABLE;
1985 static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1986 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
1988 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1989 HRESULT hr = WINED3DERR_NOTAVAILABLE;
1990 UINT nmodes;
1992 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
1993 This,
1994 Adapter,
1995 DeviceType, debug_d3ddevicetype(DeviceType),
1996 DisplayFormat, debug_d3dformat(DisplayFormat),
1997 BackBufferFormat, debug_d3dformat(BackBufferFormat),
1998 Windowed);
2000 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2001 WARN_(d3d_caps)("Adapter >= IWineD3D_GetAdapterCount(iface), returning WINED3DERR_INVALIDCALL\n");
2002 return WINED3DERR_INVALIDCALL;
2005 /* The task of this function is to check whether a certain display / backbuffer format
2006 * combination is available on the given adapter. In fullscreen mode microsoft specified
2007 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
2008 * and display format should match exactly.
2009 * In windowed mode format conversion can occur and this depends on the driver. When format
2010 * conversion is done, this function should nevertheless fail and applications need to use
2011 * CheckDeviceFormatConversion.
2012 * At the moment we assume that fullscreen and windowed have the same capabilities */
2014 /* There are only 4 display formats */
2015 if(!((DisplayFormat == WINED3DFMT_R5G6B5) ||
2016 (DisplayFormat == WINED3DFMT_X1R5G5B5) ||
2017 (DisplayFormat == WINED3DFMT_X8R8G8B8) ||
2018 (DisplayFormat == WINED3DFMT_A2R10G10B10)))
2020 TRACE_(d3d_caps)("Format %s unsupported as display format\n", debug_d3dformat(DisplayFormat));
2021 return WINED3DERR_NOTAVAILABLE;
2024 /* If the requested DisplayFormat is not available, don't continue */
2025 nmodes = IWineD3DImpl_GetAdapterModeCount(iface, Adapter, DisplayFormat);
2026 if(!nmodes) {
2027 TRACE_(d3d_caps)("No available modes for display format %s\n", debug_d3dformat(DisplayFormat));
2028 return WINED3DERR_NOTAVAILABLE;
2031 /* Windowed mode allows you to specify WINED3DFMT_UNKNOWN for the backbufferformat, it means 'reuse' the display format for the backbuffer */
2032 if(!Windowed && BackBufferFormat == WINED3DFMT_UNKNOWN) {
2033 TRACE_(d3d_caps)("BackBufferFormat WINED3FMT_UNKNOWN not available in Windowed mode\n");
2034 return WINED3DERR_NOTAVAILABLE;
2037 /* In FULLSCREEN mode R5G6B5 can only be mixed with backbuffer format R5G6B5 */
2038 if( (DisplayFormat == WINED3DFMT_R5G6B5) && (BackBufferFormat != WINED3DFMT_R5G6B5) ) {
2039 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2040 return WINED3DERR_NOTAVAILABLE;
2043 /* In FULLSCREEN mode X1R5G5B5 can only be mixed with backbuffer format *1R5G5B5 */
2044 if( (DisplayFormat == WINED3DFMT_X1R5G5B5) && !((BackBufferFormat == WINED3DFMT_X1R5G5B5) || (BackBufferFormat == WINED3DFMT_A1R5G5B5)) ) {
2045 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2046 return WINED3DERR_NOTAVAILABLE;
2049 /* In FULLSCREEN mode X8R8G8B8 can only be mixed with backbuffer format *8R8G8B8 */
2050 if( (DisplayFormat == WINED3DFMT_X8R8G8B8) && !((BackBufferFormat == WINED3DFMT_X8R8G8B8) || (BackBufferFormat == WINED3DFMT_A8R8G8B8)) ) {
2051 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2052 return WINED3DERR_NOTAVAILABLE;
2055 /* A2R10G10B10 is only allowed in fullscreen mode and it can only be mixed with backbuffer format A2R10G10B10 */
2056 if( (DisplayFormat == WINED3DFMT_A2R10G10B10) && ((BackBufferFormat != WINED3DFMT_A2R10G10B10) || Windowed)) {
2057 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2058 return WINED3DERR_NOTAVAILABLE;
2061 /* Use CheckDeviceFormat to see if the BackBufferFormat is usable with the given DisplayFormat */
2062 hr = IWineD3DImpl_CheckDeviceFormat(iface, Adapter, DeviceType, DisplayFormat, WINED3DUSAGE_RENDERTARGET, WINED3DRTYPE_SURFACE, BackBufferFormat, SURFACE_OPENGL);
2063 if(FAILED(hr))
2064 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2066 return hr;
2070 /* Check if we support bumpmapping for a format */
2071 static BOOL CheckBumpMapCapability(struct WineD3DAdapter *adapter,
2072 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
2074 const struct fragment_pipeline *fp;
2076 switch(format_desc->format)
2078 case WINED3DFMT_R8G8_SNORM:
2079 case WINED3DFMT_R16G16_SNORM:
2080 case WINED3DFMT_L6V5U5:
2081 case WINED3DFMT_X8L8V8U8:
2082 case WINED3DFMT_R8G8B8A8_SNORM:
2083 /* Ask the fixed function pipeline implementation if it can deal
2084 * with the conversion. If we've got a GL extension giving native
2085 * support this will be an identity conversion. */
2086 fp = select_fragment_implementation(adapter, DeviceType);
2087 if (fp->color_fixup_supported(format_desc->color_fixup))
2089 TRACE_(d3d_caps)("[OK]\n");
2090 return TRUE;
2092 TRACE_(d3d_caps)("[FAILED]\n");
2093 return FALSE;
2095 default:
2096 TRACE_(d3d_caps)("[FAILED]\n");
2097 return FALSE;
2101 /* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
2102 static BOOL CheckDepthStencilCapability(struct WineD3DAdapter *adapter,
2103 const struct GlPixelFormatDesc *display_format_desc, const struct GlPixelFormatDesc *ds_format_desc)
2105 int it=0;
2107 /* Only allow depth/stencil formats */
2108 if (!(ds_format_desc->Flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))) return FALSE;
2110 /* Walk through all WGL pixel formats to find a match */
2111 for (it = 0; it < adapter->nCfgs; ++it)
2113 WineD3D_PixelFormat *cfg = &adapter->cfgs[it];
2114 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, cfg, display_format_desc))
2116 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, cfg, ds_format_desc))
2118 return TRUE;
2123 return FALSE;
2126 static BOOL CheckFilterCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2128 /* The flags entry of a format contains the filtering capability */
2129 if (format_desc->Flags & WINED3DFMT_FLAG_FILTERING) return TRUE;
2131 return FALSE;
2134 /* Check the render target capabilities of a format */
2135 static BOOL CheckRenderTargetCapability(struct WineD3DAdapter *adapter,
2136 const struct GlPixelFormatDesc *adapter_format_desc, const struct GlPixelFormatDesc *check_format_desc)
2138 /* Filter out non-RT formats */
2139 if (!(check_format_desc->Flags & WINED3DFMT_FLAG_RENDERTARGET)) return FALSE;
2141 if(wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) {
2142 WineD3D_PixelFormat *cfgs = adapter->cfgs;
2143 int it;
2144 short AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
2145 short CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
2147 getColorBits(adapter_format_desc, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
2148 getColorBits(check_format_desc, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
2150 /* In backbuffer mode the front and backbuffer share the same WGL pixelformat.
2151 * The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */
2152 if(!((AdapterRed == CheckRed) && (AdapterGreen == CheckGreen) && (AdapterBlue == CheckBlue))) {
2153 TRACE_(d3d_caps)("[FAILED]\n");
2154 return FALSE;
2157 /* Check if there is a WGL pixel format matching the requirements, the format should also be window
2158 * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
2159 for (it = 0; it < adapter->nCfgs; ++it)
2161 if (cfgs[it].windowDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info,
2162 &cfgs[it], check_format_desc))
2164 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n",
2165 cfgs[it].iPixelFormat, debug_d3dformat(check_format_desc->format));
2166 return TRUE;
2169 } else if(wined3d_settings.offscreen_rendering_mode == ORM_PBUFFER) {
2170 /* We can probably use this function in FBO mode too on some drivers to get some basic indication of the capabilities. */
2171 WineD3D_PixelFormat *cfgs = adapter->cfgs;
2172 int it;
2174 /* Check if there is a WGL pixel format matching the requirements, the pixel format should also be usable with pbuffers */
2175 for (it = 0; it < adapter->nCfgs; ++it)
2177 if (cfgs[it].pbufferDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info,
2178 &cfgs[it], check_format_desc))
2180 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n",
2181 cfgs[it].iPixelFormat, debug_d3dformat(check_format_desc->format));
2182 return TRUE;
2185 } else if(wined3d_settings.offscreen_rendering_mode == ORM_FBO){
2186 /* For now return TRUE for FBOs until we have some proper checks.
2187 * Note that this function will only be called when the format is around for texturing. */
2188 return TRUE;
2190 return FALSE;
2193 static BOOL CheckSrgbReadCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2195 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
2197 /* Check for supported sRGB formats (Texture loading and framebuffer) */
2198 if(!GL_SUPPORT(EXT_TEXTURE_SRGB)) {
2199 TRACE_(d3d_caps)("[FAILED] GL_EXT_texture_sRGB not supported\n");
2200 return FALSE;
2203 switch (format_desc->format)
2205 case WINED3DFMT_A8R8G8B8:
2206 case WINED3DFMT_X8R8G8B8:
2207 case WINED3DFMT_A4R4G4B4:
2208 case WINED3DFMT_L8:
2209 case WINED3DFMT_A8L8:
2210 case WINED3DFMT_DXT1:
2211 case WINED3DFMT_DXT2:
2212 case WINED3DFMT_DXT3:
2213 case WINED3DFMT_DXT4:
2214 case WINED3DFMT_DXT5:
2215 TRACE_(d3d_caps)("[OK]\n");
2216 return TRUE;
2218 default:
2219 TRACE_(d3d_caps)("[FAILED] Gamma texture format %s not supported.\n", debug_d3dformat(format_desc->format));
2220 return FALSE;
2222 return FALSE;
2225 static BOOL CheckSrgbWriteCapability(struct WineD3DAdapter *adapter,
2226 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
2228 /* Only offer SRGB writing on X8R8G8B8/A8R8G8B8 when we use ARB or GLSL shaders as we are
2229 * doing the color fixup in shaders.
2230 * Note Windows drivers (at least on the Geforce 8800) also offer this on R5G6B5. */
2231 if ((format_desc->format == WINED3DFMT_X8R8G8B8) || (format_desc->format == WINED3DFMT_A8R8G8B8))
2233 int vs_selected_mode;
2234 int ps_selected_mode;
2235 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
2237 if((ps_selected_mode == SHADER_ARB) || (ps_selected_mode == SHADER_GLSL)) {
2238 TRACE_(d3d_caps)("[OK]\n");
2239 return TRUE;
2243 TRACE_(d3d_caps)("[FAILED] - no SRGB writing support on format=%s\n", debug_d3dformat(format_desc->format));
2244 return FALSE;
2247 /* Check if a format support blending in combination with pixel shaders */
2248 static BOOL CheckPostPixelShaderBlendingCapability(struct WineD3DAdapter *adapter,
2249 const struct GlPixelFormatDesc *format_desc)
2251 /* The flags entry of a format contains the post pixel shader blending capability */
2252 if (format_desc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING) return TRUE;
2254 return FALSE;
2257 static BOOL CheckWrapAndMipCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2259 /* OpenGL supports mipmapping on all formats basically. Wrapping is unsupported,
2260 * but we have to report mipmapping so we cannot reject this flag. Tests show that
2261 * windows reports WRAPANDMIP on unfilterable surfaces as well, apparently to show
2262 * that wrapping is supported. The lack of filtering will sort out the mipmapping
2263 * capability anyway.
2265 * For now lets report this on all formats, but in the future we may want to
2266 * restrict it to some should games need that
2268 return TRUE;
2271 /* Check if a texture format is supported on the given adapter */
2272 static BOOL CheckTextureCapability(struct WineD3DAdapter *adapter,
2273 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
2275 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
2276 const shader_backend_t *shader_backend;
2277 const struct fragment_pipeline *fp;
2279 switch (format_desc->format)
2281 /*****
2282 * supported: RGB(A) formats
2284 case WINED3DFMT_R8G8B8: /* Enable for dx7, blacklisted for 8 and 9 above */
2285 case WINED3DFMT_A8R8G8B8:
2286 case WINED3DFMT_X8R8G8B8:
2287 case WINED3DFMT_R5G6B5:
2288 case WINED3DFMT_X1R5G5B5:
2289 case WINED3DFMT_A1R5G5B5:
2290 case WINED3DFMT_A4R4G4B4:
2291 case WINED3DFMT_A8_UNORM:
2292 case WINED3DFMT_X4R4G4B4:
2293 case WINED3DFMT_R8G8B8A8_UNORM:
2294 case WINED3DFMT_X8B8G8R8:
2295 case WINED3DFMT_A2R10G10B10:
2296 case WINED3DFMT_R10G10B10A2_UNORM:
2297 case WINED3DFMT_R16G16_UNORM:
2298 TRACE_(d3d_caps)("[OK]\n");
2299 return TRUE;
2301 case WINED3DFMT_R3G3B2:
2302 TRACE_(d3d_caps)("[FAILED] - Not supported on Windows\n");
2303 return FALSE;
2305 /*****
2306 * supported: Palettized
2308 case WINED3DFMT_P8:
2309 TRACE_(d3d_caps)("[OK]\n");
2310 return TRUE;
2311 /* No Windows driver offers A8P8, so don't offer it either */
2312 case WINED3DFMT_A8P8:
2313 return FALSE;
2315 /*****
2316 * Supported: (Alpha)-Luminance
2318 case WINED3DFMT_L8:
2319 case WINED3DFMT_A8L8:
2320 case WINED3DFMT_L16:
2321 TRACE_(d3d_caps)("[OK]\n");
2322 return TRUE;
2324 /* Not supported on Windows, thus disabled */
2325 case WINED3DFMT_A4L4:
2326 TRACE_(d3d_caps)("[FAILED] - not supported on windows\n");
2327 return FALSE;
2329 /*****
2330 * Supported: Depth/Stencil formats
2332 case WINED3DFMT_D16_LOCKABLE:
2333 case WINED3DFMT_D16_UNORM:
2334 case WINED3DFMT_D15S1:
2335 case WINED3DFMT_D24X8:
2336 case WINED3DFMT_D24X4S4:
2337 case WINED3DFMT_D24S8:
2338 case WINED3DFMT_D24FS8:
2339 case WINED3DFMT_D32:
2340 case WINED3DFMT_D32F_LOCKABLE:
2341 return TRUE;
2343 /*****
2344 * Not supported everywhere(depends on GL_ATI_envmap_bumpmap or
2345 * GL_NV_texture_shader). Emulated by shaders
2347 case WINED3DFMT_R8G8_SNORM:
2348 case WINED3DFMT_X8L8V8U8:
2349 case WINED3DFMT_L6V5U5:
2350 case WINED3DFMT_R8G8B8A8_SNORM:
2351 case WINED3DFMT_R16G16_SNORM:
2352 /* Ask the shader backend if it can deal with the conversion. If
2353 * we've got a GL extension giving native support this will be an
2354 * identity conversion. */
2355 shader_backend = select_shader_backend(adapter, DeviceType);
2356 if (shader_backend->shader_color_fixup_supported(format_desc->color_fixup))
2358 TRACE_(d3d_caps)("[OK]\n");
2359 return TRUE;
2361 TRACE_(d3d_caps)("[FAILED]\n");
2362 return FALSE;
2364 case WINED3DFMT_DXT1:
2365 case WINED3DFMT_DXT2:
2366 case WINED3DFMT_DXT3:
2367 case WINED3DFMT_DXT4:
2368 case WINED3DFMT_DXT5:
2369 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
2370 TRACE_(d3d_caps)("[OK]\n");
2371 return TRUE;
2373 TRACE_(d3d_caps)("[FAILED]\n");
2374 return FALSE;
2377 /*****
2378 * Odd formats - not supported
2380 case WINED3DFMT_VERTEXDATA:
2381 case WINED3DFMT_R16_UINT:
2382 case WINED3DFMT_R32_UINT:
2383 case WINED3DFMT_R16G16B16A16_SNORM:
2384 case WINED3DFMT_A2W10V10U10:
2385 case WINED3DFMT_W11V11U10:
2386 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2387 return FALSE;
2389 /*****
2390 * WINED3DFMT_CxV8U8: Not supported right now
2392 case WINED3DFMT_CxV8U8:
2393 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2394 return FALSE;
2396 /* YUV formats */
2397 case WINED3DFMT_UYVY:
2398 case WINED3DFMT_YUY2:
2399 if(GL_SUPPORT(APPLE_YCBCR_422)) {
2400 TRACE_(d3d_caps)("[OK]\n");
2401 return TRUE;
2403 TRACE_(d3d_caps)("[FAILED]\n");
2404 return FALSE;
2405 case WINED3DFMT_YV12:
2406 TRACE_(d3d_caps)("[FAILED]\n");
2407 return FALSE;
2409 /* Not supported */
2410 case WINED3DFMT_R16G16B16A16_UNORM:
2411 case WINED3DFMT_A8R3G3B2:
2412 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2413 return FALSE;
2415 /* Floating point formats */
2416 case WINED3DFMT_R16_FLOAT:
2417 case WINED3DFMT_R16G16_FLOAT:
2418 case WINED3DFMT_R16G16B16A16_FLOAT:
2419 if(GL_SUPPORT(ARB_TEXTURE_FLOAT) && GL_SUPPORT(ARB_HALF_FLOAT_PIXEL)) {
2420 TRACE_(d3d_caps)("[OK]\n");
2421 return TRUE;
2423 TRACE_(d3d_caps)("[FAILED]\n");
2424 return FALSE;
2426 case WINED3DFMT_R32_FLOAT:
2427 case WINED3DFMT_R32G32_FLOAT:
2428 case WINED3DFMT_R32G32B32A32_FLOAT:
2429 if (GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2430 TRACE_(d3d_caps)("[OK]\n");
2431 return TRUE;
2433 TRACE_(d3d_caps)("[FAILED]\n");
2434 return FALSE;
2436 /* ATI instancing hack: Although ATI cards do not support Shader Model 3.0, they support
2437 * instancing. To query if the card supports instancing CheckDeviceFormat with the special format
2438 * MAKEFOURCC('I','N','S','T') is used. Should a (broken) app check for this provide a proper return value.
2439 * We can do instancing with all shader versions, but we need vertex shaders.
2441 * Additionally applications have to set the D3DRS_POINTSIZE render state to MAKEFOURCC('I','N','S','T') once
2442 * to enable instancing. WineD3D doesn't need that and just ignores it.
2444 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows.
2446 case WINEMAKEFOURCC('I','N','S','T'):
2447 TRACE("ATI Instancing check hack\n");
2448 if(GL_SUPPORT(ARB_VERTEX_PROGRAM) || GL_SUPPORT(ARB_VERTEX_SHADER)) {
2449 TRACE_(d3d_caps)("[OK]\n");
2450 return TRUE;
2452 TRACE_(d3d_caps)("[FAILED]\n");
2453 return FALSE;
2455 /* Some weird FOURCC formats */
2456 case WINED3DFMT_R8G8_B8G8:
2457 case WINED3DFMT_G8R8_G8B8:
2458 case WINED3DFMT_MULTI2_ARGB8:
2459 TRACE_(d3d_caps)("[FAILED]\n");
2460 return FALSE;
2462 /* Vendor specific formats */
2463 case WINED3DFMT_ATI2N:
2464 if(GL_SUPPORT(ATI_TEXTURE_COMPRESSION_3DC) || GL_SUPPORT(EXT_TEXTURE_COMPRESSION_RGTC)) {
2465 shader_backend = select_shader_backend(adapter, DeviceType);
2466 fp = select_fragment_implementation(adapter, DeviceType);
2467 if (shader_backend->shader_color_fixup_supported(format_desc->color_fixup)
2468 && fp->color_fixup_supported(format_desc->color_fixup))
2470 TRACE_(d3d_caps)("[OK]\n");
2471 return TRUE;
2474 TRACE_(d3d_caps)("[OK]\n");
2475 return TRUE;
2477 TRACE_(d3d_caps)("[FAILED]\n");
2478 return FALSE;
2480 case WINED3DFMT_NVHU:
2481 case WINED3DFMT_NVHS:
2482 /* These formats seem to be similar to the HILO formats in GL_NV_texture_shader. NVHU
2483 * is said to be GL_UNSIGNED_HILO16, NVHS GL_SIGNED_HILO16. Rumours say that d3d computes
2484 * a 3rd channel similarly to D3DFMT_CxV8U8(So NVHS could be called D3DFMT_CxV16U16).
2485 * ATI refused to support formats which can easilly be emulated with pixel shaders, so
2486 * Applications have to deal with not having NVHS and NVHU.
2488 TRACE_(d3d_caps)("[FAILED]\n");
2489 return FALSE;
2491 case WINED3DFMT_UNKNOWN:
2492 return FALSE;
2494 default:
2495 ERR("Unhandled format=%s\n", debug_d3dformat(format_desc->format));
2496 break;
2498 return FALSE;
2501 static BOOL CheckSurfaceCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *adapter_format_desc,
2502 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *check_format_desc, WINED3DSURFTYPE SurfaceType)
2504 const struct blit_shader *blitter;
2506 if(SurfaceType == SURFACE_GDI) {
2507 switch(check_format_desc->format)
2509 case WINED3DFMT_R8G8B8:
2510 case WINED3DFMT_A8R8G8B8:
2511 case WINED3DFMT_X8R8G8B8:
2512 case WINED3DFMT_R5G6B5:
2513 case WINED3DFMT_X1R5G5B5:
2514 case WINED3DFMT_A1R5G5B5:
2515 case WINED3DFMT_A4R4G4B4:
2516 case WINED3DFMT_R3G3B2:
2517 case WINED3DFMT_A8_UNORM:
2518 case WINED3DFMT_A8R3G3B2:
2519 case WINED3DFMT_X4R4G4B4:
2520 case WINED3DFMT_R10G10B10A2_UNORM:
2521 case WINED3DFMT_R8G8B8A8_UNORM:
2522 case WINED3DFMT_X8B8G8R8:
2523 case WINED3DFMT_R16G16_UNORM:
2524 case WINED3DFMT_A2R10G10B10:
2525 case WINED3DFMT_R16G16B16A16_UNORM:
2526 case WINED3DFMT_P8:
2527 TRACE_(d3d_caps)("[OK]\n");
2528 return TRUE;
2529 default:
2530 TRACE_(d3d_caps)("[FAILED] - not available on GDI surfaces\n");
2531 return FALSE;
2535 /* All format that are supported for textures are supported for surfaces as well */
2536 if (CheckTextureCapability(adapter, DeviceType, check_format_desc)) return TRUE;
2537 /* All depth stencil formats are supported on surfaces */
2538 if (CheckDepthStencilCapability(adapter, adapter_format_desc, check_format_desc)) return TRUE;
2540 /* If opengl can't process the format natively, the blitter may be able to convert it */
2541 blitter = select_blit_implementation(adapter, DeviceType);
2542 if (blitter->color_fixup_supported(check_format_desc->color_fixup))
2544 TRACE_(d3d_caps)("[OK]\n");
2545 return TRUE;
2548 /* Reject other formats */
2549 TRACE_(d3d_caps)("[FAILED]\n");
2550 return FALSE;
2553 static BOOL CheckVertexTextureCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2555 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
2557 if (!GL_LIMITS(vertex_samplers)) {
2558 TRACE_(d3d_caps)("[FAILED]\n");
2559 return FALSE;
2562 switch (format_desc->format)
2564 case WINED3DFMT_R32G32B32A32_FLOAT:
2565 if (!GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2566 TRACE_(d3d_caps)("[FAILED]\n");
2567 return FALSE;
2569 TRACE_(d3d_caps)("[OK]\n");
2570 return TRUE;
2572 default:
2573 TRACE_(d3d_caps)("[FAILED]\n");
2574 return FALSE;
2576 return FALSE;
2579 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2580 WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat,
2581 WINED3DSURFTYPE SurfaceType) {
2582 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2583 struct WineD3DAdapter *adapter = &This->adapters[Adapter];
2584 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
2585 const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(CheckFormat, gl_info);
2586 const struct GlPixelFormatDesc *adapter_format_desc = getFormatDescEntry(AdapterFormat, gl_info);
2587 DWORD UsageCaps = 0;
2589 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%u,%s,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s))\n",
2590 This,
2591 Adapter,
2592 DeviceType, debug_d3ddevicetype(DeviceType),
2593 AdapterFormat, debug_d3dformat(AdapterFormat),
2594 Usage, debug_d3dusage(Usage), debug_d3dusagequery(Usage),
2595 RType, debug_d3dresourcetype(RType),
2596 CheckFormat, debug_d3dformat(CheckFormat));
2598 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2599 return WINED3DERR_INVALIDCALL;
2602 if(RType == WINED3DRTYPE_CUBETEXTURE) {
2604 if(SurfaceType != SURFACE_OPENGL) {
2605 TRACE("[FAILED]\n");
2606 return WINED3DERR_NOTAVAILABLE;
2609 /* Cubetexture allows:
2610 * - D3DUSAGE_AUTOGENMIPMAP
2611 * - D3DUSAGE_DEPTHSTENCIL
2612 * - D3DUSAGE_DYNAMIC
2613 * - D3DUSAGE_NONSECURE (d3d9ex)
2614 * - D3DUSAGE_RENDERTARGET
2615 * - D3DUSAGE_SOFTWAREPROCESSING
2616 * - D3DUSAGE_QUERY_WRAPANDMIP
2618 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2619 /* Check if the texture format is around */
2620 if (CheckTextureCapability(adapter, DeviceType, format_desc))
2622 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
2623 /* Check for automatic mipmap generation support */
2624 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2625 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
2626 } else {
2627 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUTOGEN instead of D3D_OK */
2628 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
2632 /* Always report dynamic locking */
2633 if(Usage & WINED3DUSAGE_DYNAMIC)
2634 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2636 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2637 if(CheckRenderTargetCapability(adapter, adapter_format_desc, format_desc))
2639 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2640 } else {
2641 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2642 return WINED3DERR_NOTAVAILABLE;
2646 /* Always report software processing */
2647 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2648 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2650 /* Check QUERY_FILTER support */
2651 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2652 if (CheckFilterCapability(adapter, format_desc))
2654 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2655 } else {
2656 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2657 return WINED3DERR_NOTAVAILABLE;
2661 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2662 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2663 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
2665 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2666 } else {
2667 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2668 return WINED3DERR_NOTAVAILABLE;
2672 /* Check QUERY_SRGBREAD support */
2673 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2674 if (CheckSrgbReadCapability(adapter, format_desc))
2676 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2677 } else {
2678 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2679 return WINED3DERR_NOTAVAILABLE;
2683 /* Check QUERY_SRGBWRITE support */
2684 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2685 if (CheckSrgbWriteCapability(adapter, DeviceType, format_desc))
2687 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2688 } else {
2689 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2690 return WINED3DERR_NOTAVAILABLE;
2694 /* Check QUERY_VERTEXTEXTURE support */
2695 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2696 if (CheckVertexTextureCapability(adapter, format_desc))
2698 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2699 } else {
2700 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2701 return WINED3DERR_NOTAVAILABLE;
2705 /* Check QUERY_WRAPANDMIP support */
2706 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
2707 if (CheckWrapAndMipCapability(adapter, format_desc))
2709 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
2710 } else {
2711 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
2712 return WINED3DERR_NOTAVAILABLE;
2715 } else {
2716 TRACE_(d3d_caps)("[FAILED] - Cube texture format not supported\n");
2717 return WINED3DERR_NOTAVAILABLE;
2719 } else {
2720 TRACE_(d3d_caps)("[FAILED] - No cube texture support\n");
2721 return WINED3DERR_NOTAVAILABLE;
2723 } else if(RType == WINED3DRTYPE_SURFACE) {
2724 /* Surface allows:
2725 * - D3DUSAGE_DEPTHSTENCIL
2726 * - D3DUSAGE_NONSECURE (d3d9ex)
2727 * - D3DUSAGE_RENDERTARGET
2730 if (CheckSurfaceCapability(adapter, adapter_format_desc, DeviceType, format_desc, SurfaceType))
2732 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
2733 if (CheckDepthStencilCapability(adapter, adapter_format_desc, format_desc))
2735 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
2736 } else {
2737 TRACE_(d3d_caps)("[FAILED] - No depthstencil support\n");
2738 return WINED3DERR_NOTAVAILABLE;
2742 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2743 if (CheckRenderTargetCapability(adapter, adapter_format_desc, format_desc))
2745 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2746 } else {
2747 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2748 return WINED3DERR_NOTAVAILABLE;
2752 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2753 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2754 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
2756 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2757 } else {
2758 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2759 return WINED3DERR_NOTAVAILABLE;
2762 } else {
2763 TRACE_(d3d_caps)("[FAILED] - Not supported for plain surfaces\n");
2764 return WINED3DERR_NOTAVAILABLE;
2767 } else if(RType == WINED3DRTYPE_TEXTURE) {
2768 /* Texture allows:
2769 * - D3DUSAGE_AUTOGENMIPMAP
2770 * - D3DUSAGE_DEPTHSTENCIL
2771 * - D3DUSAGE_DMAP
2772 * - D3DUSAGE_DYNAMIC
2773 * - D3DUSAGE_NONSECURE (d3d9ex)
2774 * - D3DUSAGE_RENDERTARGET
2775 * - D3DUSAGE_SOFTWAREPROCESSING
2776 * - D3DUSAGE_TEXTAPI (d3d9ex)
2777 * - D3DUSAGE_QUERY_WRAPANDMIP
2780 if(SurfaceType != SURFACE_OPENGL) {
2781 TRACE("[FAILED]\n");
2782 return WINED3DERR_NOTAVAILABLE;
2785 /* Check if the texture format is around */
2786 if (CheckTextureCapability(adapter, DeviceType, format_desc))
2788 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
2789 /* Check for automatic mipmap generation support */
2790 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2791 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
2792 } else {
2793 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUTOGEN instead of D3D_OK */
2794 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
2798 /* Always report dynamic locking */
2799 if(Usage & WINED3DUSAGE_DYNAMIC)
2800 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2802 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2803 if (CheckRenderTargetCapability(adapter, adapter_format_desc, format_desc))
2805 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2806 } else {
2807 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2808 return WINED3DERR_NOTAVAILABLE;
2812 /* Always report software processing */
2813 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2814 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2816 /* Check QUERY_FILTER support */
2817 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2818 if (CheckFilterCapability(adapter, format_desc))
2820 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2821 } else {
2822 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2823 return WINED3DERR_NOTAVAILABLE;
2827 /* Check QUERY_LEGACYBUMPMAP support */
2828 if(Usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP) {
2829 if (CheckBumpMapCapability(adapter, DeviceType, format_desc))
2831 UsageCaps |= WINED3DUSAGE_QUERY_LEGACYBUMPMAP;
2832 } else {
2833 TRACE_(d3d_caps)("[FAILED] - No legacy bumpmap support\n");
2834 return WINED3DERR_NOTAVAILABLE;
2838 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2839 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2840 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
2842 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2843 } else {
2844 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2845 return WINED3DERR_NOTAVAILABLE;
2849 /* Check QUERY_SRGBREAD support */
2850 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2851 if (CheckSrgbReadCapability(adapter, format_desc))
2853 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2854 } else {
2855 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2856 return WINED3DERR_NOTAVAILABLE;
2860 /* Check QUERY_SRGBWRITE support */
2861 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2862 if (CheckSrgbWriteCapability(adapter, DeviceType, format_desc))
2864 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2865 } else {
2866 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2867 return WINED3DERR_NOTAVAILABLE;
2871 /* Check QUERY_VERTEXTEXTURE support */
2872 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2873 if (CheckVertexTextureCapability(adapter, format_desc))
2875 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2876 } else {
2877 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2878 return WINED3DERR_NOTAVAILABLE;
2882 /* Check QUERY_WRAPANDMIP support */
2883 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
2884 if (CheckWrapAndMipCapability(adapter, format_desc))
2886 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
2887 } else {
2888 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
2889 return WINED3DERR_NOTAVAILABLE;
2893 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
2894 if (CheckDepthStencilCapability(adapter, adapter_format_desc, format_desc))
2896 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
2897 } else {
2898 TRACE_(d3d_caps)("[FAILED] - No depth stencil support\n");
2899 return WINED3DERR_NOTAVAILABLE;
2902 } else {
2903 TRACE_(d3d_caps)("[FAILED] - Texture format not supported\n");
2904 return WINED3DERR_NOTAVAILABLE;
2906 } else if((RType == WINED3DRTYPE_VOLUME) || (RType == WINED3DRTYPE_VOLUMETEXTURE)) {
2907 /* Volume is to VolumeTexture what Surface is to Texture but its usage caps are not documented.
2908 * Most driver seem to offer (nearly) the same on Volume and VolumeTexture, so do that too.
2910 * Volumetexture allows:
2911 * - D3DUSAGE_DYNAMIC
2912 * - D3DUSAGE_NONSECURE (d3d9ex)
2913 * - D3DUSAGE_SOFTWAREPROCESSING
2914 * - D3DUSAGE_QUERY_WRAPANDMIP
2917 if(SurfaceType != SURFACE_OPENGL) {
2918 TRACE("[FAILED]\n");
2919 return WINED3DERR_NOTAVAILABLE;
2922 /* Check volume texture and volume usage caps */
2923 if(GL_SUPPORT(EXT_TEXTURE3D)) {
2924 if (!CheckTextureCapability(adapter, DeviceType, format_desc))
2926 TRACE_(d3d_caps)("[FAILED] - Format not supported\n");
2927 return WINED3DERR_NOTAVAILABLE;
2930 /* Always report dynamic locking */
2931 if(Usage & WINED3DUSAGE_DYNAMIC)
2932 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2934 /* Always report software processing */
2935 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2936 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2938 /* Check QUERY_FILTER support */
2939 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2940 if (CheckFilterCapability(adapter, format_desc))
2942 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2943 } else {
2944 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2945 return WINED3DERR_NOTAVAILABLE;
2949 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2950 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2951 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
2953 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2954 } else {
2955 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2956 return WINED3DERR_NOTAVAILABLE;
2960 /* Check QUERY_SRGBREAD support */
2961 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2962 if (CheckSrgbReadCapability(adapter, format_desc))
2964 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2965 } else {
2966 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2967 return WINED3DERR_NOTAVAILABLE;
2971 /* Check QUERY_SRGBWRITE support */
2972 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2973 if (CheckSrgbWriteCapability(adapter, DeviceType, format_desc))
2975 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2976 } else {
2977 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2978 return WINED3DERR_NOTAVAILABLE;
2982 /* Check QUERY_VERTEXTEXTURE support */
2983 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2984 if (CheckVertexTextureCapability(adapter, format_desc))
2986 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2987 } else {
2988 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2989 return WINED3DERR_NOTAVAILABLE;
2993 /* Check QUERY_WRAPANDMIP support */
2994 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
2995 if (CheckWrapAndMipCapability(adapter, format_desc))
2997 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
2998 } else {
2999 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
3000 return WINED3DERR_NOTAVAILABLE;
3003 } else {
3004 TRACE_(d3d_caps)("[FAILED] - No volume texture support\n");
3005 return WINED3DERR_NOTAVAILABLE;
3008 /* Filter formats that need conversion; For one part, this conversion is unimplemented,
3009 * and volume textures are huge, so it would be a big performance hit. Unless we hit an
3010 * app needing one of those formats, don't advertize them to avoid leading apps into
3011 * temptation. The windows drivers don't support most of those formats on volumes anyway,
3012 * except of R32F.
3014 switch(CheckFormat) {
3015 case WINED3DFMT_P8:
3016 case WINED3DFMT_A4L4:
3017 case WINED3DFMT_R32_FLOAT:
3018 case WINED3DFMT_R16_FLOAT:
3019 case WINED3DFMT_X8L8V8U8:
3020 case WINED3DFMT_L6V5U5:
3021 case WINED3DFMT_R16G16_UNORM:
3022 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
3023 return WINED3DERR_NOTAVAILABLE;
3025 case WINED3DFMT_R8G8B8A8_SNORM:
3026 case WINED3DFMT_R16G16_SNORM:
3027 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
3028 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
3029 return WINED3DERR_NOTAVAILABLE;
3031 break;
3033 case WINED3DFMT_R8G8_SNORM:
3034 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
3035 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
3036 return WINED3DERR_NOTAVAILABLE;
3038 break;
3040 case WINED3DFMT_DXT1:
3041 case WINED3DFMT_DXT2:
3042 case WINED3DFMT_DXT3:
3043 case WINED3DFMT_DXT4:
3044 case WINED3DFMT_DXT5:
3045 /* The GL_EXT_texture_compression_s3tc spec requires that loading an s3tc
3046 * compressed texture results in an error. While the D3D refrast does
3047 * support s3tc volumes, at least the nvidia windows driver does not, so
3048 * we're free not to support this format.
3050 TRACE_(d3d_caps)("[FAILED] - DXTn does not support 3D textures\n");
3051 return WINED3DERR_NOTAVAILABLE;
3053 default:
3054 /* Do nothing, continue with checking the format below */
3055 break;
3057 } else if(RType == WINED3DRTYPE_BUFFER){
3058 /* For instance vertexbuffer/indexbuffer aren't supported yet because no Windows drivers seem to offer it */
3059 TRACE_(d3d_caps)("Unhandled resource type D3DRTYPE_INDEXBUFFER / D3DRTYPE_VERTEXBUFFER\n");
3060 return WINED3DERR_NOTAVAILABLE;
3063 /* This format is nothing special and it is supported perfectly.
3064 * However, ati and nvidia driver on windows do not mark this format as
3065 * supported (tested with the dxCapsViewer) and pretending to
3066 * support this format uncovers a bug in Battlefield 1942 (fonts are missing)
3067 * So do the same as Windows drivers and pretend not to support it on dx8 and 9
3068 * Enable it on dx7. It will need additional checking on dx10 when we support it.
3070 if(This->dxVersion > 7 && CheckFormat == WINED3DFMT_R8G8B8) {
3071 TRACE_(d3d_caps)("[FAILED]\n");
3072 return WINED3DERR_NOTAVAILABLE;
3075 /* When the UsageCaps exactly matches Usage return WINED3D_OK except for the situation in which
3076 * WINED3DUSAGE_AUTOGENMIPMAP isn't around, then WINED3DOK_NOAUTOGEN is returned if all the other
3077 * usage flags match. */
3078 if(UsageCaps == Usage) {
3079 return WINED3D_OK;
3080 } else if((UsageCaps == (Usage & ~WINED3DUSAGE_AUTOGENMIPMAP)) && (Usage & WINED3DUSAGE_AUTOGENMIPMAP)){
3081 return WINED3DOK_NOAUTOGEN;
3082 } else {
3083 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);
3084 return WINED3DERR_NOTAVAILABLE;
3088 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
3089 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
3090 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3092 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))\n",
3093 This,
3094 Adapter,
3095 DeviceType, debug_d3ddevicetype(DeviceType),
3096 SourceFormat, debug_d3dformat(SourceFormat),
3097 TargetFormat, debug_d3dformat(TargetFormat));
3098 return WINED3D_OK;
3101 static const shader_backend_t *select_shader_backend(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType)
3103 const shader_backend_t *ret;
3104 int vs_selected_mode;
3105 int ps_selected_mode;
3107 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
3108 if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) {
3109 ret = &glsl_shader_backend;
3110 } else if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) {
3111 ret = &arb_program_shader_backend;
3112 } else {
3113 ret = &none_shader_backend;
3115 return ret;
3118 static const struct fragment_pipeline *select_fragment_implementation(struct WineD3DAdapter *adapter,
3119 WINED3DDEVTYPE DeviceType)
3121 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
3122 int vs_selected_mode;
3123 int ps_selected_mode;
3125 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
3126 if((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
3127 return &arbfp_fragment_pipeline;
3128 } else if(ps_selected_mode == SHADER_ATI) {
3129 return &atifs_fragment_pipeline;
3130 } else if(GL_SUPPORT(NV_REGISTER_COMBINERS) && GL_SUPPORT(NV_TEXTURE_SHADER2)) {
3131 return &nvts_fragment_pipeline;
3132 } else if(GL_SUPPORT(NV_REGISTER_COMBINERS)) {
3133 return &nvrc_fragment_pipeline;
3134 } else {
3135 return &ffp_fragment_pipeline;
3139 static const struct blit_shader *select_blit_implementation(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType)
3141 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
3142 int vs_selected_mode;
3143 int ps_selected_mode;
3145 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
3146 if((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
3147 return &arbfp_blit;
3148 } else {
3149 return &ffp_blit;
3153 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
3154 subset of a D3DCAPS9 structure. However, it has to come via a void *
3155 as the d3d8 interface cannot import the d3d9 header */
3156 static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
3158 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3159 struct WineD3DAdapter *adapter = &This->adapters[Adapter];
3160 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
3161 int vs_selected_mode;
3162 int ps_selected_mode;
3163 struct shader_caps shader_caps;
3164 struct fragment_caps fragment_caps;
3165 const shader_backend_t *shader_backend;
3166 const struct fragment_pipeline *frag_pipeline = NULL;
3167 DWORD ckey_caps, blit_caps, fx_caps;
3169 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
3171 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
3172 return WINED3DERR_INVALIDCALL;
3175 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
3177 /* This function should *not* be modifying GL caps
3178 * TODO: move the functionality where it belongs */
3179 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &adapter->gl_info);
3181 /* ------------------------------------------------
3182 The following fields apply to both d3d8 and d3d9
3183 ------------------------------------------------ */
3184 pCaps->DeviceType = (DeviceType == WINED3DDEVTYPE_HAL) ? WINED3DDEVTYPE_HAL : WINED3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
3185 pCaps->AdapterOrdinal = Adapter;
3187 pCaps->Caps = 0;
3188 pCaps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
3189 WINED3DCAPS2_FULLSCREENGAMMA |
3190 WINED3DCAPS2_DYNAMICTEXTURES;
3191 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
3192 pCaps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
3195 pCaps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
3196 WINED3DCAPS3_COPY_TO_VIDMEM |
3197 WINED3DCAPS3_COPY_TO_SYSTEMMEM;
3199 pCaps->PresentationIntervals = WINED3DPRESENT_INTERVAL_IMMEDIATE |
3200 WINED3DPRESENT_INTERVAL_ONE;
3202 pCaps->CursorCaps = WINED3DCURSORCAPS_COLOR |
3203 WINED3DCURSORCAPS_LOWRES;
3205 pCaps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
3206 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
3207 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
3208 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
3209 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
3210 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
3211 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
3212 WINED3DDEVCAPS_PUREDEVICE |
3213 WINED3DDEVCAPS_HWRASTERIZATION |
3214 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
3215 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
3216 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
3217 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
3218 WINED3DDEVCAPS_DRAWPRIMITIVES2EX |
3219 WINED3DDEVCAPS_RTPATCHES;
3221 pCaps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
3222 WINED3DPMISCCAPS_CULLCCW |
3223 WINED3DPMISCCAPS_CULLCW |
3224 WINED3DPMISCCAPS_COLORWRITEENABLE |
3225 WINED3DPMISCCAPS_CLIPTLVERTS |
3226 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
3227 WINED3DPMISCCAPS_MASKZ |
3228 WINED3DPMISCCAPS_BLENDOP |
3229 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING;
3230 /* TODO:
3231 WINED3DPMISCCAPS_NULLREFERENCE
3232 WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS
3233 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
3234 WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
3235 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
3237 if(GL_SUPPORT(EXT_BLEND_EQUATION_SEPARATE) && GL_SUPPORT(EXT_BLEND_FUNC_SEPARATE))
3238 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
3240 pCaps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
3241 WINED3DPRASTERCAPS_PAT |
3242 WINED3DPRASTERCAPS_WFOG |
3243 WINED3DPRASTERCAPS_ZFOG |
3244 WINED3DPRASTERCAPS_FOGVERTEX |
3245 WINED3DPRASTERCAPS_FOGTABLE |
3246 WINED3DPRASTERCAPS_STIPPLE |
3247 WINED3DPRASTERCAPS_SUBPIXEL |
3248 WINED3DPRASTERCAPS_ZTEST |
3249 WINED3DPRASTERCAPS_SCISSORTEST |
3250 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
3251 WINED3DPRASTERCAPS_DEPTHBIAS;
3253 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3254 pCaps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY |
3255 WINED3DPRASTERCAPS_ZBIAS |
3256 WINED3DPRASTERCAPS_MIPMAPLODBIAS;
3258 if(GL_SUPPORT(NV_FOG_DISTANCE)) {
3259 pCaps->RasterCaps |= WINED3DPRASTERCAPS_FOGRANGE;
3261 /* FIXME Add:
3262 WINED3DPRASTERCAPS_COLORPERSPECTIVE
3263 WINED3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
3264 WINED3DPRASTERCAPS_ANTIALIASEDGES
3265 WINED3DPRASTERCAPS_ZBUFFERLESSHSR
3266 WINED3DPRASTERCAPS_WBUFFER */
3268 pCaps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
3269 WINED3DPCMPCAPS_EQUAL |
3270 WINED3DPCMPCAPS_GREATER |
3271 WINED3DPCMPCAPS_GREATEREQUAL |
3272 WINED3DPCMPCAPS_LESS |
3273 WINED3DPCMPCAPS_LESSEQUAL |
3274 WINED3DPCMPCAPS_NEVER |
3275 WINED3DPCMPCAPS_NOTEQUAL;
3277 pCaps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
3278 WINED3DPBLENDCAPS_BOTHSRCALPHA |
3279 WINED3DPBLENDCAPS_DESTALPHA |
3280 WINED3DPBLENDCAPS_DESTCOLOR |
3281 WINED3DPBLENDCAPS_INVDESTALPHA |
3282 WINED3DPBLENDCAPS_INVDESTCOLOR |
3283 WINED3DPBLENDCAPS_INVSRCALPHA |
3284 WINED3DPBLENDCAPS_INVSRCCOLOR |
3285 WINED3DPBLENDCAPS_ONE |
3286 WINED3DPBLENDCAPS_SRCALPHA |
3287 WINED3DPBLENDCAPS_SRCALPHASAT |
3288 WINED3DPBLENDCAPS_SRCCOLOR |
3289 WINED3DPBLENDCAPS_ZERO;
3291 pCaps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
3292 WINED3DPBLENDCAPS_DESTCOLOR |
3293 WINED3DPBLENDCAPS_INVDESTALPHA |
3294 WINED3DPBLENDCAPS_INVDESTCOLOR |
3295 WINED3DPBLENDCAPS_INVSRCALPHA |
3296 WINED3DPBLENDCAPS_INVSRCCOLOR |
3297 WINED3DPBLENDCAPS_ONE |
3298 WINED3DPBLENDCAPS_SRCALPHA |
3299 WINED3DPBLENDCAPS_SRCCOLOR |
3300 WINED3DPBLENDCAPS_ZERO;
3301 /* NOTE: WINED3DPBLENDCAPS_SRCALPHASAT is not supported as dest blend factor,
3302 * according to the glBlendFunc manpage
3304 * WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA are
3305 * legacy settings for srcblend only
3308 if( GL_SUPPORT(EXT_BLEND_COLOR)) {
3309 pCaps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
3310 pCaps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
3314 pCaps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
3315 WINED3DPCMPCAPS_EQUAL |
3316 WINED3DPCMPCAPS_GREATER |
3317 WINED3DPCMPCAPS_GREATEREQUAL |
3318 WINED3DPCMPCAPS_LESS |
3319 WINED3DPCMPCAPS_LESSEQUAL |
3320 WINED3DPCMPCAPS_NEVER |
3321 WINED3DPCMPCAPS_NOTEQUAL;
3323 pCaps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
3324 WINED3DPSHADECAPS_COLORGOURAUDRGB |
3325 WINED3DPSHADECAPS_ALPHAFLATBLEND |
3326 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
3327 WINED3DPSHADECAPS_COLORFLATRGB |
3328 WINED3DPSHADECAPS_FOGFLAT |
3329 WINED3DPSHADECAPS_FOGGOURAUD |
3330 WINED3DPSHADECAPS_SPECULARFLATRGB;
3332 pCaps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
3333 WINED3DPTEXTURECAPS_ALPHAPALETTE |
3334 WINED3DPTEXTURECAPS_TRANSPARENCY |
3335 WINED3DPTEXTURECAPS_BORDER |
3336 WINED3DPTEXTURECAPS_MIPMAP |
3337 WINED3DPTEXTURECAPS_PROJECTED |
3338 WINED3DPTEXTURECAPS_PERSPECTIVE;
3340 if( !GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
3341 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
3342 WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
3345 if( GL_SUPPORT(EXT_TEXTURE3D)) {
3346 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP |
3347 WINED3DPTEXTURECAPS_MIPVOLUMEMAP |
3348 WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
3351 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
3352 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP |
3353 WINED3DPTEXTURECAPS_MIPCUBEMAP |
3354 WINED3DPTEXTURECAPS_CUBEMAP_POW2;
3358 pCaps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3359 WINED3DPTFILTERCAPS_MAGFPOINT |
3360 WINED3DPTFILTERCAPS_MINFLINEAR |
3361 WINED3DPTFILTERCAPS_MINFPOINT |
3362 WINED3DPTFILTERCAPS_MIPFLINEAR |
3363 WINED3DPTFILTERCAPS_MIPFPOINT |
3364 WINED3DPTFILTERCAPS_LINEAR |
3365 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3366 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3367 WINED3DPTFILTERCAPS_MIPLINEAR |
3368 WINED3DPTFILTERCAPS_MIPNEAREST |
3369 WINED3DPTFILTERCAPS_NEAREST;
3371 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3372 pCaps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
3373 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
3376 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
3377 pCaps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3378 WINED3DPTFILTERCAPS_MAGFPOINT |
3379 WINED3DPTFILTERCAPS_MINFLINEAR |
3380 WINED3DPTFILTERCAPS_MINFPOINT |
3381 WINED3DPTFILTERCAPS_MIPFLINEAR |
3382 WINED3DPTFILTERCAPS_MIPFPOINT |
3383 WINED3DPTFILTERCAPS_LINEAR |
3384 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3385 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3386 WINED3DPTFILTERCAPS_MIPLINEAR |
3387 WINED3DPTFILTERCAPS_MIPNEAREST |
3388 WINED3DPTFILTERCAPS_NEAREST;
3390 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3391 pCaps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
3392 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
3394 } else
3395 pCaps->CubeTextureFilterCaps = 0;
3397 if (GL_SUPPORT(EXT_TEXTURE3D)) {
3398 pCaps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3399 WINED3DPTFILTERCAPS_MAGFPOINT |
3400 WINED3DPTFILTERCAPS_MINFLINEAR |
3401 WINED3DPTFILTERCAPS_MINFPOINT |
3402 WINED3DPTFILTERCAPS_MIPFLINEAR |
3403 WINED3DPTFILTERCAPS_MIPFPOINT |
3404 WINED3DPTFILTERCAPS_LINEAR |
3405 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3406 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3407 WINED3DPTFILTERCAPS_MIPLINEAR |
3408 WINED3DPTFILTERCAPS_MIPNEAREST |
3409 WINED3DPTFILTERCAPS_NEAREST;
3410 } else
3411 pCaps->VolumeTextureFilterCaps = 0;
3413 pCaps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
3414 WINED3DPTADDRESSCAPS_CLAMP |
3415 WINED3DPTADDRESSCAPS_WRAP;
3417 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
3418 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
3420 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
3421 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
3423 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
3424 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
3427 if (GL_SUPPORT(EXT_TEXTURE3D)) {
3428 pCaps->VolumeTextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
3429 WINED3DPTADDRESSCAPS_CLAMP |
3430 WINED3DPTADDRESSCAPS_WRAP;
3431 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
3432 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
3434 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
3435 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
3437 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
3438 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
3440 } else
3441 pCaps->VolumeTextureAddressCaps = 0;
3443 pCaps->LineCaps = WINED3DLINECAPS_TEXTURE |
3444 WINED3DLINECAPS_ZTEST |
3445 WINED3DLINECAPS_BLEND |
3446 WINED3DLINECAPS_ALPHACMP |
3447 WINED3DLINECAPS_FOG;
3448 /* WINED3DLINECAPS_ANTIALIAS is not supported on Windows, and dx and gl seem to have a different
3449 * idea how generating the smoothing alpha values works; the result is different
3452 pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
3453 pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
3455 if(GL_SUPPORT(EXT_TEXTURE3D))
3456 pCaps->MaxVolumeExtent = GL_LIMITS(texture3d_size);
3457 else
3458 pCaps->MaxVolumeExtent = 0;
3460 pCaps->MaxTextureRepeat = 32768;
3461 pCaps->MaxTextureAspectRatio = GL_LIMITS(texture_size);
3462 pCaps->MaxVertexW = 1.0;
3464 pCaps->GuardBandLeft = 0;
3465 pCaps->GuardBandTop = 0;
3466 pCaps->GuardBandRight = 0;
3467 pCaps->GuardBandBottom = 0;
3469 pCaps->ExtentsAdjust = 0;
3471 pCaps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
3472 WINED3DSTENCILCAPS_INCRSAT |
3473 WINED3DSTENCILCAPS_INVERT |
3474 WINED3DSTENCILCAPS_KEEP |
3475 WINED3DSTENCILCAPS_REPLACE |
3476 WINED3DSTENCILCAPS_ZERO;
3477 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
3478 pCaps->StencilCaps |= WINED3DSTENCILCAPS_DECR |
3479 WINED3DSTENCILCAPS_INCR;
3481 if ( This->dxVersion > 8 &&
3482 ( GL_SUPPORT(EXT_STENCIL_TWO_SIDE) ||
3483 GL_SUPPORT(ATI_SEPARATE_STENCIL) ) ) {
3484 pCaps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
3487 pCaps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
3489 pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
3490 pCaps->MaxActiveLights = GL_LIMITS(lights);
3492 pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
3493 pCaps->MaxVertexBlendMatrixIndex = 0;
3495 pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
3496 pCaps->MaxPointSize = GL_LIMITS(pointsize);
3499 pCaps->VertexProcessingCaps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
3500 WINED3DVTXPCAPS_MATERIALSOURCE7 |
3501 WINED3DVTXPCAPS_POSITIONALLIGHTS |
3502 WINED3DVTXPCAPS_LOCALVIEWER |
3503 WINED3DVTXPCAPS_VERTEXFOG |
3504 WINED3DVTXPCAPS_TEXGEN;
3505 /* FIXME: Add
3506 D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
3508 pCaps->MaxPrimitiveCount = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
3509 pCaps->MaxVertexIndex = 0xFFFFF;
3510 pCaps->MaxStreams = MAX_STREAMS;
3511 pCaps->MaxStreamStride = 1024;
3513 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
3514 pCaps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET |
3515 WINED3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
3516 pCaps->MaxNpatchTessellationLevel = 0;
3517 pCaps->MasterAdapterOrdinal = 0;
3518 pCaps->AdapterOrdinalInGroup = 0;
3519 pCaps->NumberOfAdaptersInGroup = 1;
3521 pCaps->NumSimultaneousRTs = GL_LIMITS(buffers);
3523 pCaps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
3524 WINED3DPTFILTERCAPS_MAGFPOINT |
3525 WINED3DPTFILTERCAPS_MINFLINEAR |
3526 WINED3DPTFILTERCAPS_MAGFLINEAR;
3527 pCaps->VertexTextureFilterCaps = 0;
3529 memset(&shader_caps, 0, sizeof(shader_caps));
3530 shader_backend = select_shader_backend(adapter, DeviceType);
3531 shader_backend->shader_get_caps(DeviceType, &adapter->gl_info, &shader_caps);
3533 memset(&fragment_caps, 0, sizeof(fragment_caps));
3534 frag_pipeline = select_fragment_implementation(adapter, DeviceType);
3535 frag_pipeline->get_caps(DeviceType, &adapter->gl_info, &fragment_caps);
3537 /* Add shader misc caps. Only some of them belong to the shader parts of the pipeline */
3538 pCaps->PrimitiveMiscCaps |= fragment_caps.PrimitiveMiscCaps;
3540 /* This takes care for disabling vertex shader or pixel shader caps while leaving the other one enabled.
3541 * Ignore shader model capabilities if disabled in config
3543 if(vs_selected_mode == SHADER_NONE) {
3544 TRACE_(d3d_caps)("Vertex shader disabled in config, reporting version 0.0\n");
3545 pCaps->VertexShaderVersion = WINED3DVS_VERSION(0,0);
3546 pCaps->MaxVertexShaderConst = 0;
3547 } else {
3548 pCaps->VertexShaderVersion = shader_caps.VertexShaderVersion;
3549 pCaps->MaxVertexShaderConst = shader_caps.MaxVertexShaderConst;
3552 if(ps_selected_mode == SHADER_NONE) {
3553 TRACE_(d3d_caps)("Pixel shader disabled in config, reporting version 0.0\n");
3554 pCaps->PixelShaderVersion = WINED3DPS_VERSION(0,0);
3555 pCaps->PixelShader1xMaxValue = 0.0;
3556 } else {
3557 pCaps->PixelShaderVersion = shader_caps.PixelShaderVersion;
3558 pCaps->PixelShader1xMaxValue = shader_caps.PixelShader1xMaxValue;
3561 pCaps->TextureOpCaps = fragment_caps.TextureOpCaps;
3562 pCaps->MaxTextureBlendStages = fragment_caps.MaxTextureBlendStages;
3563 pCaps->MaxSimultaneousTextures = fragment_caps.MaxSimultaneousTextures;
3565 pCaps->VS20Caps = shader_caps.VS20Caps;
3566 pCaps->MaxVShaderInstructionsExecuted = shader_caps.MaxVShaderInstructionsExecuted;
3567 pCaps->MaxVertexShader30InstructionSlots= shader_caps.MaxVertexShader30InstructionSlots;
3568 pCaps->PS20Caps = shader_caps.PS20Caps;
3569 pCaps->MaxPShaderInstructionsExecuted = shader_caps.MaxPShaderInstructionsExecuted;
3570 pCaps->MaxPixelShader30InstructionSlots = shader_caps.MaxPixelShader30InstructionSlots;
3572 /* The following caps are shader specific, but they are things we cannot detect, or which
3573 * are the same among all shader models. So to avoid code duplication set the shader version
3574 * specific, but otherwise constant caps here
3576 if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(3,0)) {
3577 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
3578 use the VS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum VS3.0 value. */
3579 pCaps->VS20Caps.Caps = WINED3DVS20CAPS_PREDICATION;
3580 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
3581 pCaps->VS20Caps.NumTemps = max(32, adapter->gl_info.vs_arb_max_temps);
3582 pCaps->VS20Caps.StaticFlowControlDepth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH ; /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
3584 pCaps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
3585 pCaps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.vs_arb_max_instructions);
3586 } else if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(2,0)) {
3587 pCaps->VS20Caps.Caps = 0;
3588 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
3589 pCaps->VS20Caps.NumTemps = max(12, adapter->gl_info.vs_arb_max_temps);
3590 pCaps->VS20Caps.StaticFlowControlDepth = 1;
3592 pCaps->MaxVShaderInstructionsExecuted = 65535;
3593 pCaps->MaxVertexShader30InstructionSlots = 0;
3594 } else { /* VS 1.x */
3595 pCaps->VS20Caps.Caps = 0;
3596 pCaps->VS20Caps.DynamicFlowControlDepth = 0;
3597 pCaps->VS20Caps.NumTemps = 0;
3598 pCaps->VS20Caps.StaticFlowControlDepth = 0;
3600 pCaps->MaxVShaderInstructionsExecuted = 0;
3601 pCaps->MaxVertexShader30InstructionSlots = 0;
3604 if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(3,0)) {
3605 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
3606 use the PS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum PS 3.0 value. */
3608 /* 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 */
3609 pCaps->PS20Caps.Caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
3610 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
3611 WINED3DPS20CAPS_PREDICATION |
3612 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
3613 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
3614 pCaps->PS20Caps.DynamicFlowControlDepth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
3615 pCaps->PS20Caps.NumTemps = max(32, adapter->gl_info.ps_arb_max_temps);
3616 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
3617 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
3619 pCaps->MaxPShaderInstructionsExecuted = 65535;
3620 pCaps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS, adapter->gl_info.ps_arb_max_instructions);
3621 } else if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(2,0)) {
3622 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
3623 pCaps->PS20Caps.Caps = 0;
3624 pCaps->PS20Caps.DynamicFlowControlDepth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
3625 pCaps->PS20Caps.NumTemps = max(12, adapter->gl_info.ps_arb_max_temps);
3626 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
3627 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
3629 pCaps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
3630 pCaps->MaxPixelShader30InstructionSlots = 0;
3631 } else { /* PS 1.x */
3632 pCaps->PS20Caps.Caps = 0;
3633 pCaps->PS20Caps.DynamicFlowControlDepth = 0;
3634 pCaps->PS20Caps.NumTemps = 0;
3635 pCaps->PS20Caps.StaticFlowControlDepth = 0;
3636 pCaps->PS20Caps.NumInstructionSlots = 0;
3638 pCaps->MaxPShaderInstructionsExecuted = 0;
3639 pCaps->MaxPixelShader30InstructionSlots = 0;
3642 if(pCaps->VertexShaderVersion >= WINED3DVS_VERSION(2,0)) {
3643 /* OpenGL supports all the formats below, perhaps not always
3644 * without conversion, but it supports them.
3645 * Further GLSL doesn't seem to have an official unsigned type so
3646 * don't advertise it yet as I'm not sure how we handle it.
3647 * We might need to add some clamping in the shader engine to
3648 * support it.
3649 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
3650 pCaps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
3651 WINED3DDTCAPS_UBYTE4N |
3652 WINED3DDTCAPS_SHORT2N |
3653 WINED3DDTCAPS_SHORT4N;
3654 if (GL_SUPPORT(ARB_HALF_FLOAT_VERTEX)) {
3655 pCaps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
3656 WINED3DDTCAPS_FLOAT16_4;
3658 } else
3659 pCaps->DeclTypes = 0;
3661 /* Set DirectDraw helper Caps */
3662 ckey_caps = WINEDDCKEYCAPS_DESTBLT |
3663 WINEDDCKEYCAPS_SRCBLT;
3664 fx_caps = WINEDDFXCAPS_BLTALPHA |
3665 WINEDDFXCAPS_BLTMIRRORLEFTRIGHT |
3666 WINEDDFXCAPS_BLTMIRRORUPDOWN |
3667 WINEDDFXCAPS_BLTROTATION90 |
3668 WINEDDFXCAPS_BLTSHRINKX |
3669 WINEDDFXCAPS_BLTSHRINKXN |
3670 WINEDDFXCAPS_BLTSHRINKY |
3671 WINEDDFXCAPS_BLTSHRINKXN |
3672 WINEDDFXCAPS_BLTSTRETCHX |
3673 WINEDDFXCAPS_BLTSTRETCHXN |
3674 WINEDDFXCAPS_BLTSTRETCHY |
3675 WINEDDFXCAPS_BLTSTRETCHYN;
3676 blit_caps = WINEDDCAPS_BLT |
3677 WINEDDCAPS_BLTCOLORFILL |
3678 WINEDDCAPS_BLTDEPTHFILL |
3679 WINEDDCAPS_BLTSTRETCH |
3680 WINEDDCAPS_CANBLTSYSMEM |
3681 WINEDDCAPS_CANCLIP |
3682 WINEDDCAPS_CANCLIPSTRETCHED |
3683 WINEDDCAPS_COLORKEY |
3684 WINEDDCAPS_COLORKEYHWASSIST |
3685 WINEDDCAPS_ALIGNBOUNDARYSRC;
3687 /* Fill the ddraw caps structure */
3688 pCaps->DirectDrawCaps.Caps = WINEDDCAPS_GDI |
3689 WINEDDCAPS_PALETTE |
3690 blit_caps;
3691 pCaps->DirectDrawCaps.Caps2 = WINEDDCAPS2_CERTIFIED |
3692 WINEDDCAPS2_NOPAGELOCKREQUIRED |
3693 WINEDDCAPS2_PRIMARYGAMMA |
3694 WINEDDCAPS2_WIDESURFACES |
3695 WINEDDCAPS2_CANRENDERWINDOWED;
3696 pCaps->DirectDrawCaps.SVBCaps = blit_caps;
3697 pCaps->DirectDrawCaps.SVBCKeyCaps = ckey_caps;
3698 pCaps->DirectDrawCaps.SVBFXCaps = fx_caps;
3699 pCaps->DirectDrawCaps.VSBCaps = blit_caps;
3700 pCaps->DirectDrawCaps.VSBCKeyCaps = ckey_caps;
3701 pCaps->DirectDrawCaps.VSBFXCaps = fx_caps;
3702 pCaps->DirectDrawCaps.SSBCaps = blit_caps;
3703 pCaps->DirectDrawCaps.SSBCKeyCaps = ckey_caps;
3704 pCaps->DirectDrawCaps.SSBFXCaps = fx_caps;
3706 pCaps->DirectDrawCaps.ddsCaps = WINEDDSCAPS_ALPHA |
3707 WINEDDSCAPS_BACKBUFFER |
3708 WINEDDSCAPS_FLIP |
3709 WINEDDSCAPS_FRONTBUFFER |
3710 WINEDDSCAPS_OFFSCREENPLAIN |
3711 WINEDDSCAPS_PALETTE |
3712 WINEDDSCAPS_PRIMARYSURFACE |
3713 WINEDDSCAPS_SYSTEMMEMORY |
3714 WINEDDSCAPS_VIDEOMEMORY |
3715 WINEDDSCAPS_VISIBLE;
3716 pCaps->DirectDrawCaps.StrideAlign = DDRAW_PITCH_ALIGNMENT;
3718 /* Set D3D caps if OpenGL is available. */
3719 if (adapter->opengl)
3721 pCaps->DirectDrawCaps.ddsCaps |=WINEDDSCAPS_3DDEVICE |
3722 WINEDDSCAPS_MIPMAP |
3723 WINEDDSCAPS_TEXTURE |
3724 WINEDDSCAPS_ZBUFFER;
3725 pCaps->DirectDrawCaps.Caps |= WINEDDCAPS_3D;
3728 return WINED3D_OK;
3731 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
3732 and fields being inserted in the middle, a new structure is used in place */
3733 static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter,
3734 WINED3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviourFlags, IUnknown *parent,
3735 IWineD3DDeviceParent *device_parent, IWineD3DDevice **ppReturnedDeviceInterface)
3737 IWineD3DDeviceImpl *object = NULL;
3738 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3739 struct WineD3DAdapter *adapter = &This->adapters[Adapter];
3740 WINED3DDISPLAYMODE mode;
3741 const struct fragment_pipeline *frag_pipeline = NULL;
3742 int i;
3743 struct fragment_caps ffp_caps;
3744 struct shader_caps shader_caps;
3745 HRESULT hr;
3747 /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
3748 * number and create a device without a 3D adapter for 2D only operation.
3750 if (IWineD3D_GetAdapterCount(iface) && Adapter >= IWineD3D_GetAdapterCount(iface)) {
3751 return WINED3DERR_INVALIDCALL;
3754 /* Create a WineD3DDevice object */
3755 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
3756 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
3757 TRACE("Created WineD3DDevice object @ %p\n", object);
3758 if (NULL == object) {
3759 return WINED3DERR_OUTOFVIDEOMEMORY;
3762 /* Set up initial COM information */
3763 object->lpVtbl = &IWineD3DDevice_Vtbl;
3764 object->ref = 1;
3765 object->wineD3D = iface;
3766 object->adapter = This->adapter_count ? adapter : NULL;
3767 IWineD3D_AddRef(object->wineD3D);
3768 object->parent = parent;
3769 object->device_parent = device_parent;
3770 list_init(&object->resources);
3771 list_init(&object->shaders);
3773 if(This->dxVersion == 7) {
3774 object->surface_alignment = DDRAW_PITCH_ALIGNMENT;
3775 } else {
3776 object->surface_alignment = D3D8_PITCH_ALIGNMENT;
3778 object->posFixup[0] = 1.0; /* This is needed to get the x coord unmodified through a MAD */
3780 /* Set the state up as invalid until the device is fully created */
3781 object->state = WINED3DERR_DRIVERINTERNALERROR;
3783 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %x, RetDevInt: %p)\n", This, Adapter, DeviceType,
3784 hFocusWindow, BehaviourFlags, ppReturnedDeviceInterface);
3786 /* Save the creation parameters */
3787 object->createParms.AdapterOrdinal = Adapter;
3788 object->createParms.DeviceType = DeviceType;
3789 object->createParms.hFocusWindow = hFocusWindow;
3790 object->createParms.BehaviorFlags = BehaviourFlags;
3792 /* Initialize other useful values */
3793 object->adapterNo = Adapter;
3794 object->devType = DeviceType;
3796 select_shader_mode(&adapter->gl_info, DeviceType,
3797 &object->ps_selected_mode, &object->vs_selected_mode);
3798 object->shader_backend = select_shader_backend(adapter, DeviceType);
3800 memset(&shader_caps, 0, sizeof(shader_caps));
3801 object->shader_backend->shader_get_caps(DeviceType, &adapter->gl_info, &shader_caps);
3802 object->d3d_vshader_constantF = shader_caps.MaxVertexShaderConst;
3803 object->d3d_pshader_constantF = shader_caps.MaxPixelShaderConst;
3804 object->vs_clipping = shader_caps.VSClipping;
3806 memset(&ffp_caps, 0, sizeof(ffp_caps));
3807 frag_pipeline = select_fragment_implementation(adapter, DeviceType);
3808 object->frag_pipe = frag_pipeline;
3809 frag_pipeline->get_caps(DeviceType, &adapter->gl_info, &ffp_caps);
3810 object->max_ffp_textures = ffp_caps.MaxSimultaneousTextures;
3811 object->max_ffp_texture_stages = ffp_caps.MaxTextureBlendStages;
3812 hr = compile_state_table(object->StateTable, object->multistate_funcs, &adapter->gl_info,
3813 ffp_vertexstate_template, frag_pipeline, misc_state_template);
3815 if (FAILED(hr)) {
3816 IWineD3D_Release(object->wineD3D);
3817 HeapFree(GetProcessHeap(), 0, object);
3819 return hr;
3822 object->blitter = select_blit_implementation(adapter, DeviceType);
3824 /* set the state of the device to valid */
3825 object->state = WINED3D_OK;
3827 /* Get the initial screen setup for ddraw */
3828 IWineD3DImpl_GetAdapterDisplayMode(iface, Adapter, &mode);
3830 object->ddraw_width = mode.Width;
3831 object->ddraw_height = mode.Height;
3832 object->ddraw_format = mode.Format;
3834 for(i = 0; i < PATCHMAP_SIZE; i++) {
3835 list_init(&object->patches[i]);
3838 IWineD3DDeviceParent_WineD3DDeviceCreated(device_parent, *ppReturnedDeviceInterface);
3840 return WINED3D_OK;
3843 static HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
3844 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3845 IUnknown_AddRef(This->parent);
3846 *pParent = This->parent;
3847 return WINED3D_OK;
3850 ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface) {
3851 IUnknown* surfaceParent;
3852 TRACE("(%p) call back\n", pSurface);
3854 /* Now, release the parent, which will take care of cleaning up the surface for us */
3855 IWineD3DSurface_GetParent(pSurface, &surfaceParent);
3856 IUnknown_Release(surfaceParent);
3857 return IUnknown_Release(surfaceParent);
3860 ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pVolume) {
3861 IUnknown* volumeParent;
3862 TRACE("(%p) call back\n", pVolume);
3864 /* Now, release the parent, which will take care of cleaning up the volume for us */
3865 IWineD3DVolume_GetParent(pVolume, &volumeParent);
3866 IUnknown_Release(volumeParent);
3867 return IUnknown_Release(volumeParent);
3870 static BOOL match_apple(const WineD3D_GL_Info *gl_info)
3872 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
3873 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
3874 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
3876 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
3877 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
3878 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
3879 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
3880 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
3881 * the chance that other implementations support them is rather small since Win32 QuickTime uses
3882 * DirectDraw, not OpenGL.
3884 if(gl_info->supported[APPLE_FENCE] &&
3885 gl_info->supported[APPLE_CLIENT_STORAGE] &&
3886 gl_info->supported[APPLE_FLUSH_RENDER] &&
3887 gl_info->supported[APPLE_YCBCR_422]) {
3888 TRACE_(d3d_caps)("GL_APPLE_fence, GL_APPLE_client_storage, GL_APPLE_flush_render and GL_ycbcr_422 are supported\n");
3889 TRACE_(d3d_caps)("Activating MacOS fixups\n");
3890 return TRUE;
3891 } else {
3892 TRACE_(d3d_caps)("Apple extensions are not supported\n");
3893 TRACE_(d3d_caps)("Not activating MacOS fixups\n");
3894 return FALSE;
3898 static void test_pbo_functionality(WineD3D_GL_Info *gl_info) {
3899 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
3900 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
3901 * all the texture. This function detects this bug by its symptom and disables PBOs
3902 * if the test fails.
3904 * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
3905 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
3906 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
3907 * read back is compared to the original. If they are equal PBOs are assumed to work,
3908 * otherwise the PBO extension is disabled.
3910 GLuint texture, pbo;
3911 static const unsigned int pattern[] = {
3912 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
3913 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
3914 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
3915 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
3917 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
3919 if(!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) {
3920 /* No PBO -> No point in testing them */
3921 return;
3924 ENTER_GL();
3926 while(glGetError());
3927 glGenTextures(1, &texture);
3928 glBindTexture(GL_TEXTURE_2D, texture);
3930 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
3931 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
3932 checkGLcall("Specifying the PBO test texture\n");
3934 GL_EXTCALL(glGenBuffersARB(1, &pbo));
3935 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
3936 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
3937 checkGLcall("Specifying the PBO test pbo\n");
3939 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
3940 checkGLcall("Loading the PBO test texture\n");
3942 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
3943 glFinish(); /* just to be sure */
3945 memset(check, 0, sizeof(check));
3946 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
3947 checkGLcall("Reading back the PBO test texture\n");
3949 glDeleteTextures(1, &texture);
3950 GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
3951 checkGLcall("PBO test cleanup\n");
3953 LEAVE_GL();
3955 if(memcmp(check, pattern, sizeof(check)) != 0) {
3956 WARN_(d3d_caps)("PBO test failed, read back data doesn't match original\n");
3957 WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance\n");
3958 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
3959 } else {
3960 TRACE_(d3d_caps)("PBO test successful\n");
3964 /* Certain applications(Steam) complain if we report an outdated driver version. In general,
3965 * reporting a driver version is moot because we are not the Windows driver, and we have different
3966 * bugs, features, etc.
3968 * If a card is not found in this table, the gl driver version is reported
3970 struct driver_version_information {
3971 WORD vendor; /* reported PCI card vendor ID */
3972 WORD card; /* reported PCI card device ID */
3973 const char *description; /* Description of the card e.g. NVIDIA RIVA TNT */
3974 WORD hipart_hi, hipart_lo; /* driver hiword to report */
3975 WORD lopart_hi, lopart_lo; /* driver loword to report */
3978 static const struct driver_version_information driver_version_table[] = {
3979 /* Nvidia drivers. Geforce6 and newer cards are supported by the current driver (180.x)
3980 * 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
3981 * Geforce2MX/3/4 up to 96.x - driver uses numbering 9.6.8.9 for 96.89
3982 * TNT/Geforce1/2 up to 71.x - driver uses numbering 7.1.8.6 for 71.86
3984 * All version numbers used below are from the Linux nvidia drivers.
3986 {VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT, "NVIDIA RIVA TNT", 7, 1, 8, 6 },
3987 {VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT2, "NVIDIA RIVA TNT2/TNT2 Pro", 7, 1, 8, 6 },
3988 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE, "NVIDIA GeForce 256", 7, 1, 8, 6 },
3989 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2_MX, "NVIDIA GeForce2 MX/MX 400", 9, 6, 4, 3 },
3990 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2, "NVIDIA GeForce2 GTS/GeForce2 Pro", 7, 1, 8, 6 },
3991 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE3, "NVIDIA GeForce3", 9, 6, 4, 3 },
3992 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_MX, "NVIDIA GeForce4 MX 460", 9, 6, 4, 3 },
3993 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_TI4200, "NVIDIA GeForce4 Ti 4200", 9, 6, 4, 3 },
3994 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, "NVIDIA GeForce FX 5200", 7, 15, 11, 7341 },
3995 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, "NVIDIA GeForce FX 5600", 7, 15, 11, 7341 },
3996 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, "NVIDIA GeForce FX 5800", 7, 15, 11, 7341 },
3997 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, "NVIDIA GeForce 6200", 7, 15, 11, 8044 },
3998 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, "NVIDIA GeForce 6600 GT", 7, 15, 11, 8044 },
3999 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, "NVIDIA GeForce 6800", 7, 15, 11, 8044 },
4000 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, "NVIDIA GeForce Go 7300", 7, 15, 11, 8044 },
4001 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, "NVIDIA GeForce Go 7400", 7, 15, 11, 8044 },
4002 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, "NVIDIA GeForce 7600 GT", 7, 15, 11, 8044 },
4003 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, "NVIDIA GeForce 7800 GT", 7, 15, 11, 8044 },
4004 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, "NVIDIA GeForce 8300 GS", 7, 15, 11, 8044 },
4005 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, "NVIDIA GeForce 8600 GT", 7, 15, 11, 8044 },
4006 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, "NVIDIA GeForce 8600M GT", 7, 15, 11, 8044 },
4007 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, "NVIDIA GeForce 8800 GTS", 7, 15, 11, 8044 },
4008 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9200, "NVIDIA GeForce 9200", 7, 15, 11, 8044 },
4009 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400GT, "NVIDIA GeForce 9400 GT", 7, 15, 11, 8044 },
4010 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9500GT, "NVIDIA GeForce 9500 GT", 7, 15, 11, 8044 },
4011 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9600GT, "NVIDIA GeForce 9600 GT", 7, 15, 11, 8044 },
4012 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9800GT, "NVIDIA GeForce 9800 GT", 7, 15, 11, 8044 },
4013 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX260, "NVIDIA GeForce GTX 260", 7, 15, 11, 8044 },
4014 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX275, "NVIDIA GeForce GTX 275", 7, 15, 11, 8044 },
4015 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX280, "NVIDIA GeForce GTX 280", 7, 15, 11, 8044 },
4017 /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode */
4018 {VENDOR_ATI, CARD_ATI_RADEON_9500, "ATI Radeon 9500", 6, 14, 10, 6764 },
4019 {VENDOR_ATI, CARD_ATI_RADEON_X700, "ATI Radeon X700 SE", 6, 14, 10, 6764 },
4020 {VENDOR_ATI, CARD_ATI_RADEON_X1600, "ATI Radeon X1600 Series", 6, 14, 10, 6764 },
4021 {VENDOR_ATI, CARD_ATI_RADEON_HD2300, "ATI Mobility Radeon HD 2300", 6, 14, 10, 6764 },
4022 {VENDOR_ATI, CARD_ATI_RADEON_HD2600, "ATI Mobility Radeon HD 2600", 6, 14, 10, 6764 },
4023 {VENDOR_ATI, CARD_ATI_RADEON_HD2900, "ATI Radeon HD 2900 XT", 6, 14, 10, 6764 },
4024 {VENDOR_ATI, CARD_ATI_RADEON_HD4800, "ATI Radeon HD 4800 Series", 6, 14, 10, 6764 },
4026 /* TODO: Add information about legacy ATI hardware, Intel and other cards */
4029 static BOOL match_ati_r300_to_500(const WineD3D_GL_Info *gl_info) {
4030 if(gl_info->gl_vendor != VENDOR_ATI) return FALSE;
4031 if(gl_info->gl_card == CARD_ATI_RADEON_9500) return TRUE;
4032 if(gl_info->gl_card == CARD_ATI_RADEON_X700) return TRUE;
4033 if(gl_info->gl_card == CARD_ATI_RADEON_X1600) return TRUE;
4034 return FALSE;
4037 static BOOL match_geforce5(const WineD3D_GL_Info *gl_info) {
4038 if(gl_info->gl_vendor == VENDOR_NVIDIA) {
4039 if(gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5800 || gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5600) {
4040 return TRUE;
4043 return FALSE;
4046 static BOOL match_apple_intel(const WineD3D_GL_Info *gl_info) {
4047 return gl_info->gl_vendor == VENDOR_INTEL && match_apple(gl_info);
4050 static BOOL match_apple_nonr500ati(const WineD3D_GL_Info *gl_info) {
4051 if(!match_apple(gl_info)) return FALSE;
4052 if(gl_info->gl_vendor != VENDOR_ATI) return FALSE;
4053 if(gl_info->gl_card == CARD_ATI_RADEON_X1600) return FALSE;
4054 return TRUE;
4057 static BOOL match_fglrx(const WineD3D_GL_Info *gl_info) {
4058 if(gl_info->gl_vendor != VENDOR_ATI) return FALSE;
4059 if(match_apple(gl_info)) return FALSE;
4060 if(strstr(gl_info->gl_renderer, "DRI")) return FALSE; /* Filter out Mesa DRI drivers */
4061 return TRUE;
4064 static BOOL match_dx10_capable(const WineD3D_GL_Info *gl_info) {
4065 /* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
4066 * 44 varyings. So assume that if we have more than 44 varyings we have a dx10 card.
4067 * This detection is for the gl_ClipPos varying quirk. If a d3d9 card really supports more than 44
4068 * varyings and we subtract one in dx9 shaders its not going to hurt us because the dx9 limit is
4069 * hardcoded
4071 * dx10 cards usually have 64 varyings
4073 return gl_info->max_glsl_varyings > 44;
4076 static void quirk_arb_constants(WineD3D_GL_Info *gl_info) {
4077 TRACE_(d3d_caps)("Using ARB vs constant limit(=%u) for GLSL\n", gl_info->vs_arb_constantsF);
4078 gl_info->vs_glsl_constantsF = gl_info->vs_arb_constantsF;
4079 TRACE_(d3d_caps)("Using ARB ps constant limit(=%u) for GLSL\n", gl_info->ps_arb_constantsF);
4080 gl_info->ps_glsl_constantsF = gl_info->ps_arb_constantsF;
4083 static void quirk_apple_glsl_constants(WineD3D_GL_Info *gl_info) {
4084 quirk_arb_constants(gl_info);
4085 /* MacOS needs uniforms for relative addressing offsets. This can accumulate to quite a few uniforms.
4086 * Beyond that the general uniform isn't optimal, so reserve a number of uniforms. 12 vec4's should
4087 * allow 48 different offsets or other helper immediate values
4089 TRACE_(d3d_caps)("Reserving 12 GLSL constants for compiler private use\n");
4090 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
4093 /* fglrx crashes with a very bad kernel panic if GL_POINT_SPRITE_ARB is set to GL_COORD_REPLACE_ARB
4094 * on more than one texture unit. This means that the d3d9 visual point size test will cause a
4095 * kernel panic on any machine running fglrx 9.3(latest that supports r300 to r500 cards). This
4096 * quirk only enables point sprites on the first texture unit. This keeps point sprites working in
4097 * most games, but avoids the crash
4099 * A more sophisticated way would be to find all units that need texture coordinates and enable
4100 * point sprites for one if only one is found, and software emulate point sprites in drawStridedSlow
4101 * if more than one unit needs texture coordinates(This requires software ffp and vertex shaders though)
4103 * Note that disabling the extension entirely does not gain predictability because there is no point
4104 * sprite capability flag in d3d, so the potential rendering bugs are the same if we disable the extension.
4106 static void quirk_one_point_sprite(WineD3D_GL_Info *gl_info) {
4107 if(gl_info->supported[ARB_POINT_SPRITE]) {
4108 TRACE("Limiting point sprites to one texture unit\n");
4109 gl_info->max_point_sprite_units = 1;
4113 static void quirk_ati_dx9(WineD3D_GL_Info *gl_info) {
4114 quirk_arb_constants(gl_info);
4116 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
4117 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
4118 * If real NP2 textures are used, the driver falls back to software. We could just remove the
4119 * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconventient
4120 * due to the non-normalized texture coordinates. Thus set an internal extension flag,
4121 * GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures
4122 * as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits.
4124 * fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it advertises opengl 2.0 which
4125 * has this extension promoted to core. The extension loading code sets this extension supported
4126 * due to that, so this code works on fglrx as well.
4128 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing\n");
4129 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
4130 gl_info->supported[WINE_NORMALIZED_TEXRECT] = TRUE;
4132 /* fglrx has the same structural issues as the one described in quirk_apple_glsl_constants, although
4133 * it is generally more efficient. Reserve just 8 constants
4135 TRACE_(d3d_caps)("Reserving 8 GLSL constants for compiler private use\n");
4136 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 8);
4139 static void quirk_no_np2(WineD3D_GL_Info *gl_info) {
4140 /* The nVidia GeForceFX series reports OpenGL 2.0 capabilities with the latest drivers versions, but
4141 * doesn't explicitly advertise the ARB_tex_npot extension in the GL extension string.
4142 * This usually means that ARB_tex_npot is supported in hardware as long as the application is staying
4143 * within the limits enforced by the ARB_texture_rectangle extension. This however is not true for the
4144 * FX series, which instantly falls back to a slower software path as soon as ARB_tex_npot is used.
4145 * We therefore completely remove ARB_tex_npot from the list of supported extensions.
4147 * Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot,
4148 * triggering the software fallback. There is not much we can do here apart from disabling the
4149 * software-emulated extension and reenable ARB_tex_rect (which was previously disabled
4150 * in IWineD3DImpl_FillGLCaps).
4151 * This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer
4152 * post-processing effects in the game "Max Payne 2").
4153 * The behaviour can be verified through a simple test app attached in bugreport #14724.
4155 TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing\n");
4156 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
4157 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
4160 static void quirk_texcoord_w(WineD3D_GL_Info *gl_info) {
4161 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
4162 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
4163 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
4164 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
4165 * according to the spec.
4167 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
4168 * makes the shader slower and eats instruction slots which should be available to the d3d app.
4170 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
4171 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
4172 * this workaround is activated on cards that do not need it, it won't break things, just affect
4173 * performance negatively.
4175 TRACE("Enabling vertex texture coord fixes in vertex shaders\n");
4176 gl_info->set_texcoord_w = TRUE;
4179 static void quirk_clip_varying(WineD3D_GL_Info *gl_info) {
4180 gl_info->glsl_clip_varying = TRUE;
4183 struct driver_quirk quirk_table[] = {
4185 match_ati_r300_to_500,
4186 quirk_ati_dx9,
4187 "ATI GLSL constant and normalized texrect quirk"
4189 /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
4190 * used it falls back to software. While the compiler can detect if the shader uses all declared
4191 * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
4192 * using relative addressing falls back to software.
4194 * ARB vp gives the correct amount of uniforms, so use it instead of GLSL
4197 match_apple,
4198 quirk_apple_glsl_constants,
4199 "Apple GLSL uniform override"
4202 match_geforce5,
4203 quirk_no_np2,
4204 "Geforce 5 NP2 disable"
4207 match_apple_intel,
4208 quirk_texcoord_w,
4209 "Init texcoord .w for Apple Intel GPU driver"
4212 match_apple_nonr500ati,
4213 quirk_texcoord_w,
4214 "Init texcoord .w for Apple ATI >= r600 GPU driver"
4217 match_fglrx,
4218 quirk_one_point_sprite,
4219 "Fglrx point sprite crash workaround"
4222 match_dx10_capable,
4223 quirk_clip_varying,
4224 "Reserved varying for gl_ClipPos"
4228 static void fixup_extensions(WineD3D_GL_Info *gl_info) {
4229 unsigned int i;
4231 for(i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); i++) {
4232 if(!quirk_table[i].match(gl_info)) continue;
4233 TRACE_(d3d_caps)("Applying driver quirk \"%s\"\n", quirk_table[i].description);
4234 quirk_table[i].apply(gl_info);
4237 /* Find out if PBOs work as they are supposed to */
4238 test_pbo_functionality(gl_info);
4240 /* Fixup the driver version */
4241 for(i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++) {
4242 if(gl_info->gl_vendor == driver_version_table[i].vendor &&
4243 gl_info->gl_card == driver_version_table[i].card) {
4244 TRACE_(d3d_caps)("Found card 0x%04x, 0x%04x in driver version DB\n", gl_info->gl_vendor, gl_info->gl_card);
4246 gl_info->driver_version = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
4247 driver_version_table[i].lopart_lo);
4248 gl_info->driver_version_hipart = MAKEDWORD_VERSION(driver_version_table[i].hipart_hi,
4249 driver_version_table[i].hipart_lo);
4250 strcpy(gl_info->driver_description, driver_version_table[i].description);
4251 break;
4256 static void WINE_GLAPI invalid_func(const void *data)
4258 ERR("Invalid vertex attribute function called\n");
4259 DebugBreak();
4262 static void WINE_GLAPI invalid_texcoord_func(GLenum unit, const void *data)
4264 ERR("Invalid texcoord function called\n");
4265 DebugBreak();
4268 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
4269 * the extension detection and are used in drawStridedSlow
4271 static void WINE_GLAPI position_d3dcolor(const void *data)
4273 DWORD pos = *((const DWORD *)data);
4275 FIXME("Add a test for fixed function position from d3dcolor type\n");
4276 glVertex4s(D3DCOLOR_B_R(pos),
4277 D3DCOLOR_B_G(pos),
4278 D3DCOLOR_B_B(pos),
4279 D3DCOLOR_B_A(pos));
4282 static void WINE_GLAPI position_float4(const void *data)
4284 const GLfloat *pos = data;
4286 if (pos[3] < eps && pos[3] > -eps)
4287 glVertex3fv(pos);
4288 else {
4289 float w = 1.0 / pos[3];
4291 glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
4295 static void WINE_GLAPI diffuse_d3dcolor(const void *data)
4297 DWORD diffuseColor = *((const DWORD *)data);
4299 glColor4ub(D3DCOLOR_B_R(diffuseColor),
4300 D3DCOLOR_B_G(diffuseColor),
4301 D3DCOLOR_B_B(diffuseColor),
4302 D3DCOLOR_B_A(diffuseColor));
4305 static void WINE_GLAPI specular_d3dcolor(const void *data)
4307 DWORD specularColor = *((const DWORD *)data);
4308 GLbyte d[] = {D3DCOLOR_B_R(specularColor),
4309 D3DCOLOR_B_G(specularColor),
4310 D3DCOLOR_B_B(specularColor)};
4312 specular_func_3ubv(d);
4315 static void WINE_GLAPI warn_no_specular_func(const void *data)
4317 WARN("GL_EXT_secondary_color not supported\n");
4320 static void fillGLAttribFuncs(const WineD3D_GL_Info *gl_info)
4322 position_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4323 position_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4324 position_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)glVertex3fv;
4325 position_funcs[WINED3D_FFP_EMIT_FLOAT4] = position_float4;
4326 position_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = position_d3dcolor;
4327 position_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4328 position_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4329 position_funcs[WINED3D_FFP_EMIT_SHORT4] = (glAttribFunc)glVertex2sv;
4330 position_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4331 position_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4332 position_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4333 position_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4334 position_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4335 position_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4336 position_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4337 position_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4338 position_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4340 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4341 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4342 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)glColor3fv;
4343 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glAttribFunc)glColor4fv;
4344 diffuse_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = diffuse_d3dcolor;
4345 diffuse_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4346 diffuse_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4347 diffuse_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4348 diffuse_funcs[WINED3D_FFP_EMIT_UBYTE4N] = (glAttribFunc)glColor4ubv;
4349 diffuse_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4350 diffuse_funcs[WINED3D_FFP_EMIT_SHORT4N] = (glAttribFunc)glColor4sv;
4351 diffuse_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4352 diffuse_funcs[WINED3D_FFP_EMIT_USHORT4N] = (glAttribFunc)glColor4usv;
4353 diffuse_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4354 diffuse_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4355 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4356 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4358 /* No 4 component entry points here */
4359 specular_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4360 specular_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4361 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
4362 specular_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)GL_EXTCALL(glSecondaryColor3fvEXT);
4363 } else {
4364 specular_funcs[WINED3D_FFP_EMIT_FLOAT3] = warn_no_specular_func;
4366 specular_funcs[WINED3D_FFP_EMIT_FLOAT4] = invalid_func;
4367 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
4368 specular_func_3ubv = (glAttribFunc)GL_EXTCALL(glSecondaryColor3ubvEXT);
4369 specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = specular_d3dcolor;
4370 } else {
4371 specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = warn_no_specular_func;
4373 specular_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4374 specular_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4375 specular_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4376 specular_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4377 specular_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4378 specular_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4379 specular_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4380 specular_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4381 specular_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4382 specular_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4383 specular_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4384 specular_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4386 /* Only 3 component entry points here. Test how others behave. Float4 normals are used
4387 * by one of our tests, trying to pass it to the pixel shader, which fails on Windows.
4389 normal_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4390 normal_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4391 normal_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)glNormal3fv;
4392 normal_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glAttribFunc)glNormal3fv; /* Just ignore the 4th value */
4393 normal_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_func;
4394 normal_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4395 normal_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4396 normal_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4397 normal_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4398 normal_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4399 normal_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4400 normal_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4401 normal_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4402 normal_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4403 normal_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4404 normal_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4405 normal_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4407 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT1] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord1fvARB);
4408 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2fvARB);
4409 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord3fvARB);
4410 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4fvARB);
4411 multi_texcoord_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_texcoord_func;
4412 multi_texcoord_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_texcoord_func;
4413 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2svARB);
4414 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4svARB);
4415 multi_texcoord_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_texcoord_func;
4416 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_texcoord_func;
4417 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_texcoord_func;
4418 multi_texcoord_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_texcoord_func;
4419 multi_texcoord_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_texcoord_func;
4420 multi_texcoord_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_texcoord_func;
4421 multi_texcoord_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_texcoord_func;
4422 if (GL_SUPPORT(NV_HALF_FLOAT))
4424 /* Not supported by ARB_HALF_FLOAT_VERTEX, so check for NV_HALF_FLOAT */
4425 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2hvNV);
4426 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4hvNV);
4427 } else {
4428 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_texcoord_func;
4429 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_texcoord_func;
4433 BOOL InitAdapters(IWineD3DImpl *This)
4435 static HMODULE mod_gl;
4436 BOOL ret;
4437 int ps_selected_mode, vs_selected_mode;
4439 /* No need to hold any lock. The calling library makes sure only one thread calls
4440 * wined3d simultaneously
4443 TRACE("Initializing adapters\n");
4445 if(!mod_gl) {
4446 #ifdef USE_WIN32_OPENGL
4447 #define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
4448 mod_gl = LoadLibraryA("opengl32.dll");
4449 if(!mod_gl) {
4450 ERR("Can't load opengl32.dll!\n");
4451 goto nogl_adapter;
4453 #else
4454 #define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
4455 /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
4456 mod_gl = GetModuleHandleA("gdi32.dll");
4457 #endif
4460 /* Load WGL core functions from opengl32.dll */
4461 #define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn);
4462 WGL_FUNCS_GEN;
4463 #undef USE_WGL_FUNC
4465 if(!pwglGetProcAddress) {
4466 ERR("Unable to load wglGetProcAddress!\n");
4467 goto nogl_adapter;
4470 /* Dynamically load all GL core functions */
4471 GL_FUNCS_GEN;
4472 #undef USE_GL_FUNC
4474 /* Load glFinish and glFlush from opengl32.dll even if we're not using WIN32 opengl
4475 * otherwise because we have to use winex11.drv's override
4477 #ifdef USE_WIN32_OPENGL
4478 glFinish = (void*)GetProcAddress(mod_gl, "glFinish");
4479 glFlush = (void*)GetProcAddress(mod_gl, "glFlush");
4480 #else
4481 glFinish = (void*)pwglGetProcAddress("wglFinish");
4482 glFlush = (void*)pwglGetProcAddress("wglFlush");
4483 #endif
4485 glEnableWINE = glEnable;
4486 glDisableWINE = glDisable;
4488 /* For now only one default adapter */
4490 struct WineD3DAdapter *adapter = &This->adapters[0];
4491 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
4492 int iPixelFormat;
4493 int res;
4494 int i;
4495 WineD3D_PixelFormat *cfgs;
4496 DISPLAY_DEVICEW DisplayDevice;
4497 HDC hdc;
4499 TRACE("Initializing default adapter\n");
4500 adapter->num = 0;
4501 adapter->monitorPoint.x = -1;
4502 adapter->monitorPoint.y = -1;
4504 if (!WineD3D_CreateFakeGLContext()) {
4505 ERR("Failed to get a gl context for default adapter\n");
4506 WineD3D_ReleaseFakeGLContext();
4507 goto nogl_adapter;
4510 ret = IWineD3DImpl_FillGLCaps(&adapter->gl_info);
4511 if(!ret) {
4512 ERR("Failed to initialize gl caps for default adapter\n");
4513 WineD3D_ReleaseFakeGLContext();
4514 goto nogl_adapter;
4516 ret = initPixelFormats(&adapter->gl_info);
4517 if(!ret) {
4518 ERR("Failed to init gl formats\n");
4519 WineD3D_ReleaseFakeGLContext();
4520 goto nogl_adapter;
4523 hdc = pwglGetCurrentDC();
4524 if(!hdc) {
4525 ERR("Failed to get gl HDC\n");
4526 WineD3D_ReleaseFakeGLContext();
4527 goto nogl_adapter;
4530 adapter->driver = "Display";
4531 adapter->description = "Direct3D HAL";
4533 /* Use the VideoRamSize registry setting when set */
4534 if(wined3d_settings.emulated_textureram)
4535 adapter->TextureRam = wined3d_settings.emulated_textureram;
4536 else
4537 adapter->TextureRam = adapter->gl_info.vidmem;
4538 adapter->UsedTextureRam = 0;
4539 TRACE("Emulating %dMB of texture ram\n", adapter->TextureRam/(1024*1024));
4541 /* Initialize the Adapter's DeviceName which is required for ChangeDisplaySettings and friends */
4542 DisplayDevice.cb = sizeof(DisplayDevice);
4543 EnumDisplayDevicesW(NULL, 0 /* Adapter 0 = iDevNum 0 */, &DisplayDevice, 0);
4544 TRACE("DeviceName: %s\n", debugstr_w(DisplayDevice.DeviceName));
4545 strcpyW(adapter->DeviceName, DisplayDevice.DeviceName);
4547 if(GL_SUPPORT(WGL_ARB_PIXEL_FORMAT))
4549 int attribute;
4550 int attribs[10];
4551 int values[10];
4552 int nAttribs = 0;
4554 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
4555 GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, &attribute, &adapter->nCfgs));
4557 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, adapter->nCfgs *sizeof(WineD3D_PixelFormat));
4558 cfgs = adapter->cfgs;
4559 attribs[nAttribs++] = WGL_RED_BITS_ARB;
4560 attribs[nAttribs++] = WGL_GREEN_BITS_ARB;
4561 attribs[nAttribs++] = WGL_BLUE_BITS_ARB;
4562 attribs[nAttribs++] = WGL_ALPHA_BITS_ARB;
4563 attribs[nAttribs++] = WGL_DEPTH_BITS_ARB;
4564 attribs[nAttribs++] = WGL_STENCIL_BITS_ARB;
4565 attribs[nAttribs++] = WGL_DRAW_TO_WINDOW_ARB;
4566 attribs[nAttribs++] = WGL_PIXEL_TYPE_ARB;
4567 attribs[nAttribs++] = WGL_DOUBLE_BUFFER_ARB;
4568 attribs[nAttribs++] = WGL_AUX_BUFFERS_ARB;
4570 for (iPixelFormat=1; iPixelFormat <= adapter->nCfgs; ++iPixelFormat)
4572 res = GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, nAttribs, attribs, values));
4574 if(!res)
4575 continue;
4577 /* Cache the pixel format */
4578 cfgs->iPixelFormat = iPixelFormat;
4579 cfgs->redSize = values[0];
4580 cfgs->greenSize = values[1];
4581 cfgs->blueSize = values[2];
4582 cfgs->alphaSize = values[3];
4583 cfgs->depthSize = values[4];
4584 cfgs->stencilSize = values[5];
4585 cfgs->windowDrawable = values[6];
4586 cfgs->iPixelType = values[7];
4587 cfgs->doubleBuffer = values[8];
4588 cfgs->auxBuffers = values[9];
4590 cfgs->pbufferDrawable = FALSE;
4591 /* Check for pbuffer support when it is around as wglGetPixelFormatAttribiv fails for unknown attributes. */
4592 if(GL_SUPPORT(WGL_ARB_PBUFFER)) {
4593 int attrib = WGL_DRAW_TO_PBUFFER_ARB;
4594 int value;
4595 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 1, &attrib, &value)))
4596 cfgs->pbufferDrawable = value;
4599 cfgs->numSamples = 0;
4600 /* Check multisample support */
4601 if(GL_SUPPORT(ARB_MULTISAMPLE)) {
4602 int attrib[2] = {WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB};
4603 int value[2];
4604 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 2, attrib, value))) {
4605 /* value[0] = WGL_SAMPLE_BUFFERS_ARB which tells whether multisampling is supported.
4606 * value[1] = number of multi sample buffers*/
4607 if(value[0])
4608 cfgs->numSamples = value[1];
4612 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);
4613 cfgs++;
4616 else
4618 int nCfgs = DescribePixelFormat(hdc, 0, 0, 0);
4619 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nCfgs*sizeof(WineD3D_PixelFormat));
4620 adapter->nCfgs = 0; /* We won't accept all formats e.g. software accelerated ones will be skipped */
4622 cfgs = adapter->cfgs;
4623 for(iPixelFormat=1; iPixelFormat<=nCfgs; iPixelFormat++)
4625 PIXELFORMATDESCRIPTOR ppfd;
4627 res = DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &ppfd);
4628 if(!res)
4629 continue;
4631 /* We only want HW acceleration using an OpenGL ICD driver.
4632 * PFD_GENERIC_FORMAT = slow opengl 1.1 gdi software rendering
4633 * PFD_GENERIC_ACCELERATED = partial hw acceleration using a MCD driver (e.g. 3dfx minigl)
4635 if(ppfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED))
4637 TRACE("Skipping iPixelFormat=%d because it isn't ICD accelerated\n", iPixelFormat);
4638 continue;
4641 cfgs->iPixelFormat = iPixelFormat;
4642 cfgs->redSize = ppfd.cRedBits;
4643 cfgs->greenSize = ppfd.cGreenBits;
4644 cfgs->blueSize = ppfd.cBlueBits;
4645 cfgs->alphaSize = ppfd.cAlphaBits;
4646 cfgs->depthSize = ppfd.cDepthBits;
4647 cfgs->stencilSize = ppfd.cStencilBits;
4648 cfgs->pbufferDrawable = 0;
4649 cfgs->windowDrawable = (ppfd.dwFlags & PFD_DRAW_TO_WINDOW) ? 1 : 0;
4650 cfgs->iPixelType = (ppfd.iPixelType == PFD_TYPE_RGBA) ? WGL_TYPE_RGBA_ARB : WGL_TYPE_COLORINDEX_ARB;
4651 cfgs->doubleBuffer = (ppfd.dwFlags & PFD_DOUBLEBUFFER) ? 1 : 0;
4652 cfgs->auxBuffers = ppfd.cAuxBuffers;
4653 cfgs->numSamples = 0;
4655 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);
4656 cfgs++;
4657 adapter->nCfgs++;
4660 /* 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 */
4661 if(!adapter->nCfgs)
4663 ERR("Disabling Direct3D because no hardware accelerated pixel formats have been found!\n");
4665 WineD3D_ReleaseFakeGLContext();
4666 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
4667 goto nogl_adapter;
4671 /* D16, D24X8 and D24S8 are common depth / depth+stencil formats. All drivers support them though this doesn't
4672 * mean that the format is offered in hardware. For instance Geforce8 cards don't have offer D16 in hardware
4673 * but just fake it using D24(X8?) which is fine. D3D also allows that.
4674 * Some display drivers (i915 on Linux) only report mixed depth+stencil formats like D24S8. MSDN clearly mentions
4675 * that only on lockable formats (e.g. D16_locked) the bit order is guaranteed and that on other formats the
4676 * driver is allowed to consume more bits EXCEPT for stencil bits.
4678 * Mark an adapter with this broken stencil behavior.
4680 adapter->brokenStencil = TRUE;
4681 for (i = 0, cfgs = adapter->cfgs; i < adapter->nCfgs; ++i)
4683 /* Nearly all drivers offer depth formats without stencil, only on i915 this if-statement won't be entered. */
4684 if(cfgs[i].depthSize && !cfgs[i].stencilSize) {
4685 adapter->brokenStencil = FALSE;
4686 break;
4690 fixup_extensions(&adapter->gl_info);
4691 add_gl_compat_wrappers(&adapter->gl_info);
4693 WineD3D_ReleaseFakeGLContext();
4695 select_shader_mode(&adapter->gl_info, WINED3DDEVTYPE_HAL, &ps_selected_mode, &vs_selected_mode);
4696 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &adapter->gl_info);
4697 fillGLAttribFuncs(&adapter->gl_info);
4698 adapter->opengl = TRUE;
4700 This->adapter_count = 1;
4701 TRACE("%u adapters successfully initialized\n", This->adapter_count);
4703 return TRUE;
4705 nogl_adapter:
4706 /* Initialize an adapter for ddraw-only memory counting */
4707 memset(This->adapters, 0, sizeof(This->adapters));
4708 This->adapters[0].num = 0;
4709 This->adapters[0].opengl = FALSE;
4710 This->adapters[0].monitorPoint.x = -1;
4711 This->adapters[0].monitorPoint.y = -1;
4713 This->adapters[0].driver = "Display";
4714 This->adapters[0].description = "WineD3D DirectDraw Emulation";
4715 if(wined3d_settings.emulated_textureram) {
4716 This->adapters[0].TextureRam = wined3d_settings.emulated_textureram;
4717 } else {
4718 This->adapters[0].TextureRam = 8 * 1024 * 1024; /* This is plenty for a DDraw-only card */
4721 initPixelFormatsNoGL(&This->adapters[0].gl_info);
4723 This->adapter_count = 1;
4724 return FALSE;
4727 /**********************************************************
4728 * IWineD3D VTbl follows
4729 **********************************************************/
4731 const IWineD3DVtbl IWineD3D_Vtbl =
4733 /* IUnknown */
4734 IWineD3DImpl_QueryInterface,
4735 IWineD3DImpl_AddRef,
4736 IWineD3DImpl_Release,
4737 /* IWineD3D */
4738 IWineD3DImpl_GetParent,
4739 IWineD3DImpl_GetAdapterCount,
4740 IWineD3DImpl_RegisterSoftwareDevice,
4741 IWineD3DImpl_GetAdapterMonitor,
4742 IWineD3DImpl_GetAdapterModeCount,
4743 IWineD3DImpl_EnumAdapterModes,
4744 IWineD3DImpl_GetAdapterDisplayMode,
4745 IWineD3DImpl_GetAdapterIdentifier,
4746 IWineD3DImpl_CheckDeviceMultiSampleType,
4747 IWineD3DImpl_CheckDepthStencilMatch,
4748 IWineD3DImpl_CheckDeviceType,
4749 IWineD3DImpl_CheckDeviceFormat,
4750 IWineD3DImpl_CheckDeviceFormatConversion,
4751 IWineD3DImpl_GetDeviceCaps,
4752 IWineD3DImpl_CreateDevice