wined3d: Get rid of DEBUG_SINGLE_MODE.
[wine/hacks.git] / dlls / wined3d / directx.c
blob25fd4d4f0bf7f78ee2be7bfbeb04bc7c5a910e21
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 #include "config.h"
26 #include <assert.h>
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
30 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
32 #define GLINFO_LOCATION (*gl_info)
34 /* The d3d device ID */
35 static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
37 /* Extension detection */
38 static const struct {
39 const char *extension_string;
40 GL_SupportedExt extension;
41 DWORD version;
42 } EXTENSION_MAP[] = {
43 /* APPLE */
44 {"GL_APPLE_client_storage", APPLE_CLIENT_STORAGE, 0 },
45 {"GL_APPLE_fence", APPLE_FENCE, 0 },
46 {"GL_APPLE_flush_render", APPLE_FLUSH_RENDER, 0 },
47 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422, 0 },
48 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS, 0 },
50 /* ATI */
51 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL, 0 },
52 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3, 0 },
53 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE, 0 },
54 {"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER, 0 },
55 {"GL_ATI_texture_compression_3dc", ATI_TEXTURE_COMPRESSION_3DC, 0 },
57 /* ARB */
58 {"GL_ARB_color_buffer_float", ARB_COLOR_BUFFER_FLOAT, 0 },
59 {"GL_ARB_depth_buffer_float", ARB_DEPTH_BUFFER_FLOAT, 0 },
60 {"GL_ARB_depth_texture", ARB_DEPTH_TEXTURE, 0 },
61 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS, 0 },
62 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM, 0 },
63 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER, 0 },
64 {"GL_ARB_geometry_shader4", ARB_GEOMETRY_SHADER4, 0 },
65 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL, 0 },
66 {"GL_ARB_imaging", ARB_IMAGING, 0 },
67 {"GL_ARB_multisample", ARB_MULTISAMPLE, 0 }, /* needs GLX_ARB_MULTISAMPLE as well */
68 {"GL_ARB_multitexture", ARB_MULTITEXTURE, 0 },
69 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY, 0 },
70 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT, 0 },
71 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS, 0 },
72 {"GL_ARB_point_sprite", ARB_POINT_SPRITE, 0 },
73 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP, 0 },
74 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION, 0 },
75 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP, 0 },
76 {"GL_ARB_texture_env_add", ARB_TEXTURE_ENV_ADD, 0 },
77 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE, 0 },
78 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3, 0 },
79 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT, 0 },
80 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT, 0 },
81 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO, MAKEDWORD_VERSION(2, 0) },
82 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE, 0 },
83 {"GL_ARB_texture_rg", ARB_TEXTURE_RG, 0 },
84 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND, 0 },
85 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT, 0 },
86 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM, 0 },
87 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER, 0 },
88 {"GL_ARB_shader_objects", ARB_SHADER_OBJECTS, 0 },
89 {"GL_ARB_shader_texture_lod", ARB_SHADER_TEXTURE_LOD, 0 },
90 {"GL_ARB_half_float_vertex", ARB_HALF_FLOAT_VERTEX, 0 },
92 /* EXT */
93 {"GL_EXT_blend_color", EXT_BLEND_COLOR, 0 },
94 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX, 0 },
95 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE, 0 },
96 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE, 0 },
97 {"GL_EXT_fog_coord", EXT_FOG_COORD, 0 },
98 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT, 0 },
99 {"GL_EXT_framebuffer_multisample", EXT_FRAMEBUFFER_MULTISAMPLE, 0 },
100 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT, 0 },
101 {"GL_EXT_packed_depth_stencil", EXT_PACKED_DEPTH_STENCIL, 0 },
102 {"GL_EXT_paletted_texture", EXT_PALETTED_TEXTURE, 0 },
103 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS, 0 },
104 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR, 0 },
105 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE, 0 },
106 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP, 0 },
107 {"GL_EXT_texture3D", EXT_TEXTURE3D, MAKEDWORD_VERSION(1, 2) },
108 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC, 0 },
109 {"GL_EXT_texture_compression_rgtc", EXT_TEXTURE_COMPRESSION_RGTC, 0 },
110 {"GL_EXT_texture_env_add", EXT_TEXTURE_ENV_ADD, 0 },
111 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE, 0 },
112 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3, 0 },
113 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB, 0 },
114 {"GL_EXT_texture_swizzle", EXT_TEXTURE_SWIZZLE, 0 },
115 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC, 0 },
116 {"GL_EXT_texture_lod", EXT_TEXTURE_LOD, 0 },
117 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS, 0 },
118 {"GL_EXT_vertex_array_bgra", EXT_VERTEX_ARRAY_BGRA, 0 },
119 {"GL_EXT_vertex_shader", EXT_VERTEX_SHADER, 0 },
120 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS, 0 },
122 /* NV */
123 {"GL_NV_half_float", NV_HALF_FLOAT, 0 },
124 {"GL_NV_fence", NV_FENCE, 0 },
125 {"GL_NV_fog_distance", NV_FOG_DISTANCE, 0 },
126 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM, 0 },
127 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2, 0 },
128 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS, 0 },
129 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2, 0 },
130 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION, 0 },
131 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4, 0 },
132 {"GL_NV_texture_shader", NV_TEXTURE_SHADER, 0 },
133 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2, 0 },
134 {"GL_NV_texture_shader3", NV_TEXTURE_SHADER3, 0 },
135 {"GL_NV_occlusion_query", NV_OCCLUSION_QUERY, 0 },
136 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM, 0 },
137 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1, 0 },
138 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2, 0 },
139 {"GL_NV_vertex_program2_option", NV_VERTEX_PROGRAM2_OPTION, 0 },
140 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3, 0 },
141 {"GL_NV_fragment_program_option", NV_FRAGMENT_PROGRAM_OPTION, 0 },
142 {"GL_NV_depth_clamp", NV_DEPTH_CLAMP, 0 },
143 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT, 0 },
145 /* SGI */
146 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP, 0 },
149 /**********************************************************
150 * Utility functions follow
151 **********************************************************/
153 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat, WINED3DSURFTYPE SurfaceType);
154 static const struct fragment_pipeline *select_fragment_implementation(struct WineD3DAdapter *adapter,
155 WINED3DDEVTYPE DeviceType);
156 static const shader_backend_t *select_shader_backend(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType);
157 static const struct blit_shader *select_blit_implementation(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType);
159 /* lookup tables */
160 const int minLookup[MAX_LOOKUPS] =
162 WINED3DTADDRESS_WRAP, /* WINELOOKUP_WARPPARAM */
165 const int maxLookup[MAX_LOOKUPS] =
167 WINED3DTADDRESS_MIRRORONCE, /* WINELOOKUP_WARPPARAM */
170 DWORD *stateLookup[MAX_LOOKUPS];
172 struct min_lookup minMipLookup[WINED3DTEXF_ANISOTROPIC + 1];
173 const struct min_lookup minMipLookup_noFilter[WINED3DTEXF_ANISOTROPIC + 1] =
175 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}},
176 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}},
177 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}},
178 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}},
181 GLenum magLookup[WINED3DTEXF_ANISOTROPIC + 1];
182 const GLenum magLookup_noFilter[WINED3DTEXF_ANISOTROPIC + 1] =
184 GL_NEAREST, GL_NEAREST, GL_NEAREST, GL_NEAREST
187 /* drawStridedSlow attributes */
188 glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT];
189 glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT];
190 glAttribFunc specular_func_3ubv;
191 glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT];
192 glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT];
193 glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT];
196 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created,
197 * i.e., there is no GL Context - Get a default rendering context to enable the
198 * function query some info from GL.
201 static int wined3d_fake_gl_context_ref = 0;
202 static BOOL wined3d_fake_gl_context_foreign;
203 static BOOL wined3d_fake_gl_context_available = FALSE;
204 static HDC wined3d_fake_gl_context_hdc = NULL;
205 static HWND wined3d_fake_gl_context_hwnd = NULL;
207 static CRITICAL_SECTION wined3d_fake_gl_context_cs;
208 static CRITICAL_SECTION_DEBUG wined3d_fake_gl_context_cs_debug =
210 0, 0, &wined3d_fake_gl_context_cs,
211 { &wined3d_fake_gl_context_cs_debug.ProcessLocksList,
212 &wined3d_fake_gl_context_cs_debug.ProcessLocksList },
213 0, 0, { (DWORD_PTR)(__FILE__ ": wined3d_fake_gl_context_cs") }
215 static CRITICAL_SECTION wined3d_fake_gl_context_cs = { &wined3d_fake_gl_context_cs_debug, -1, 0, 0, 0, 0 };
217 static void WineD3D_ReleaseFakeGLContext(void) {
218 HGLRC glCtx;
220 EnterCriticalSection(&wined3d_fake_gl_context_cs);
222 if(!wined3d_fake_gl_context_available) {
223 TRACE_(d3d_caps)("context not available\n");
224 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
225 return;
228 glCtx = pwglGetCurrentContext();
230 TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref);
231 if (0 == (--wined3d_fake_gl_context_ref) ) {
232 if(!wined3d_fake_gl_context_foreign && glCtx) {
233 TRACE_(d3d_caps)("destroying fake GL context\n");
234 pwglMakeCurrent(NULL, NULL);
235 pwglDeleteContext(glCtx);
237 if(wined3d_fake_gl_context_hdc)
238 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
239 wined3d_fake_gl_context_hdc = NULL; /* Make sure we don't think that it is still around */
240 if(wined3d_fake_gl_context_hwnd)
241 DestroyWindow(wined3d_fake_gl_context_hwnd);
242 wined3d_fake_gl_context_hwnd = NULL;
243 wined3d_fake_gl_context_available = FALSE;
245 assert(wined3d_fake_gl_context_ref >= 0);
247 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
250 static BOOL WineD3D_CreateFakeGLContext(void) {
251 HGLRC glCtx = NULL;
253 EnterCriticalSection(&wined3d_fake_gl_context_cs);
255 TRACE("getting context...\n");
256 if(wined3d_fake_gl_context_ref > 0) goto ret;
257 assert(0 == wined3d_fake_gl_context_ref);
259 wined3d_fake_gl_context_foreign = TRUE;
261 glCtx = pwglGetCurrentContext();
262 if (!glCtx) {
263 PIXELFORMATDESCRIPTOR pfd;
264 int iPixelFormat;
266 wined3d_fake_gl_context_foreign = FALSE;
268 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes */
269 wined3d_fake_gl_context_hwnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window", WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
270 if(!wined3d_fake_gl_context_hwnd) {
271 ERR("HWND creation failed!\n");
272 goto fail;
274 wined3d_fake_gl_context_hdc = GetDC(wined3d_fake_gl_context_hwnd);
275 if(!wined3d_fake_gl_context_hdc) {
276 ERR("GetDC failed!\n");
277 goto fail;
280 /* PixelFormat selection */
281 ZeroMemory(&pfd, sizeof(pfd));
282 pfd.nSize = sizeof(pfd);
283 pfd.nVersion = 1;
284 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;/*PFD_GENERIC_ACCELERATED*/
285 pfd.iPixelType = PFD_TYPE_RGBA;
286 pfd.cColorBits = 32;
287 pfd.iLayerType = PFD_MAIN_PLANE;
289 iPixelFormat = ChoosePixelFormat(wined3d_fake_gl_context_hdc, &pfd);
290 if(!iPixelFormat) {
291 /* If this happens something is very wrong as ChoosePixelFormat barely fails */
292 ERR("Can't find a suitable iPixelFormat\n");
293 goto fail;
295 DescribePixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, sizeof(pfd), &pfd);
296 SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd);
298 /* Create a GL context */
299 glCtx = pwglCreateContext(wined3d_fake_gl_context_hdc);
300 if (!glCtx) {
301 WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
302 goto fail;
305 /* Make it the current GL context */
306 if (!pwglMakeCurrent(wined3d_fake_gl_context_hdc, glCtx)) {
307 WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
308 goto fail;
312 ret:
313 TRACE("incrementing ref from %i\n", wined3d_fake_gl_context_ref);
314 wined3d_fake_gl_context_ref++;
315 wined3d_fake_gl_context_available = TRUE;
316 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
317 return TRUE;
318 fail:
319 if(wined3d_fake_gl_context_hdc)
320 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
321 wined3d_fake_gl_context_hdc = NULL;
322 if(wined3d_fake_gl_context_hwnd)
323 DestroyWindow(wined3d_fake_gl_context_hwnd);
324 wined3d_fake_gl_context_hwnd = NULL;
325 if(glCtx) pwglDeleteContext(glCtx);
326 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
327 return FALSE;
330 /* Adjust the amount of used texture memory */
331 long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram){
332 struct WineD3DAdapter *adapter = D3DDevice->adapter;
334 adapter->UsedTextureRam += glram;
335 TRACE("Adjusted gl ram by %ld to %d\n", glram, adapter->UsedTextureRam);
336 return adapter->UsedTextureRam;
339 /**********************************************************
340 * IUnknown parts follows
341 **********************************************************/
343 static HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
345 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
347 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
348 if (IsEqualGUID(riid, &IID_IUnknown)
349 || IsEqualGUID(riid, &IID_IWineD3DBase)
350 || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
351 IUnknown_AddRef(iface);
352 *ppobj = This;
353 return S_OK;
355 *ppobj = NULL;
356 return E_NOINTERFACE;
359 static ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
360 IWineD3DImpl *This = (IWineD3DImpl *)iface;
361 ULONG refCount = InterlockedIncrement(&This->ref);
363 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
364 return refCount;
367 static ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
368 IWineD3DImpl *This = (IWineD3DImpl *)iface;
369 ULONG ref;
370 TRACE("(%p) : Releasing from %d\n", This, This->ref);
371 ref = InterlockedDecrement(&This->ref);
372 if (ref == 0) {
373 unsigned int i;
375 for (i = 0; i < This->adapter_count; ++i)
377 HeapFree(GetProcessHeap(), 0, This->adapters[i].cfgs);
379 HeapFree(GetProcessHeap(), 0, This);
382 return ref;
385 /* Set the shader type for this device, depending on the given capabilities,
386 * the device type, and the user preferences in wined3d_settings */
388 static void select_shader_mode(const WineD3D_GL_Info *gl_info, WINED3DDEVTYPE DeviceType, int *ps_selected, int *vs_selected)
390 if (wined3d_settings.vs_mode == VS_NONE) {
391 *vs_selected = SHADER_NONE;
392 } else if (gl_info->supported[ARB_VERTEX_SHADER] && wined3d_settings.glslRequested) {
393 /* Geforce4 cards support GLSL but for vertex shaders only. Further its reported GLSL caps are
394 * wrong. This combined with the fact that glsl won't offer more features or performance, use ARB
395 * shaders only on this card. */
396 if(gl_info->vs_nv_version && gl_info->vs_nv_version < VS_VERSION_20)
397 *vs_selected = SHADER_ARB;
398 else
399 *vs_selected = SHADER_GLSL;
400 } else if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
401 *vs_selected = SHADER_ARB;
402 } else {
403 *vs_selected = SHADER_NONE;
406 if (wined3d_settings.ps_mode == PS_NONE) {
407 *ps_selected = SHADER_NONE;
408 } else if (gl_info->supported[ARB_FRAGMENT_SHADER] && wined3d_settings.glslRequested) {
409 *ps_selected = SHADER_GLSL;
410 } else if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
411 *ps_selected = SHADER_ARB;
412 } else if (gl_info->supported[ATI_FRAGMENT_SHADER]) {
413 *ps_selected = SHADER_ATI;
414 } else {
415 *ps_selected = SHADER_NONE;
419 /** Select the number of report maximum shader constants based on the selected shader modes */
420 static void select_shader_max_constants(
421 int ps_selected_mode,
422 int vs_selected_mode,
423 WineD3D_GL_Info *gl_info) {
425 switch (vs_selected_mode) {
426 case SHADER_GLSL:
427 gl_info->max_vshader_constantsF = gl_info->vs_glsl_constantsF;
428 break;
429 case SHADER_ARB:
430 gl_info->max_vshader_constantsF = gl_info->vs_arb_constantsF;
431 break;
432 default:
433 gl_info->max_vshader_constantsF = 0;
434 break;
437 switch (ps_selected_mode) {
438 case SHADER_GLSL:
439 gl_info->max_pshader_constantsF = gl_info->ps_glsl_constantsF;
440 break;
441 case SHADER_ARB:
442 gl_info->max_pshader_constantsF = gl_info->ps_arb_constantsF;
443 break;
444 default:
445 gl_info->max_pshader_constantsF = 0;
446 break;
450 /**********************************************************
451 * IWineD3D parts follows
452 **********************************************************/
454 /* GL locking is done by the caller */
455 static inline BOOL test_arb_vs_offset_limit(const WineD3D_GL_Info *gl_info)
457 GLuint prog;
458 BOOL ret = FALSE;
459 const char *testcode =
460 "!!ARBvp1.0\n"
461 "PARAM C[66] = { program.env[0..65] };\n"
462 "ADDRESS A0;"
463 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
464 "ARL A0.x, zero.x;\n"
465 "MOV result.position, C[A0.x + 65];\n"
466 "END\n";
468 while(glGetError());
469 GL_EXTCALL(glGenProgramsARB(1, &prog));
470 if(!prog) {
471 ERR("Failed to create an ARB offset limit test program\n");
473 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
474 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
475 strlen(testcode), testcode));
476 if(glGetError() != 0) {
477 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
478 TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
479 ret = TRUE;
480 } else TRACE("OpenGL implementation allows offsets > 63\n");
482 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
483 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
484 checkGLcall("ARB vp offset limit test cleanup\n");
486 return ret;
489 static DWORD ver_for_ext(GL_SupportedExt ext)
491 unsigned int i;
492 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
493 if(EXTENSION_MAP[i].extension == ext) {
494 return EXTENSION_MAP[i].version;
497 return 0;
500 static BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
501 const char *GL_Extensions = NULL;
502 const char *WGL_Extensions = NULL;
503 const char *gl_string = NULL;
504 const char *gl_string_cursor = NULL;
505 GLint gl_max;
506 GLfloat gl_floatv[2];
507 int major = 1, minor = 0;
508 BOOL return_value = TRUE;
509 unsigned i;
510 HDC hdc;
511 unsigned int vidmem=0;
513 TRACE_(d3d_caps)("(%p)\n", gl_info);
515 ENTER_GL();
517 gl_string = (const char *) glGetString(GL_RENDERER);
518 if (!gl_string) gl_string = "None";
519 strcpy(gl_info->gl_renderer, gl_string);
521 gl_string = (const char *) glGetString(GL_VENDOR);
522 TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
523 if (gl_string != NULL) {
524 /* Fill in the GL vendor */
525 if (strstr(gl_string, "NVIDIA")) {
526 gl_info->gl_vendor = VENDOR_NVIDIA;
527 } else if (strstr(gl_string, "ATI")) {
528 gl_info->gl_vendor = VENDOR_ATI;
529 } else if (strstr(gl_string, "Intel(R)") ||
530 strstr(gl_info->gl_renderer, "Intel(R)") ||
531 strstr(gl_string, "Intel Inc.")) {
532 gl_info->gl_vendor = VENDOR_INTEL;
533 } else if (strstr(gl_string, "Mesa")) {
534 gl_info->gl_vendor = VENDOR_MESA;
535 } else {
536 gl_info->gl_vendor = VENDOR_WINE;
538 } else {
539 gl_info->gl_vendor = VENDOR_WINE;
543 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
545 /* Parse the GL_VERSION field into major and minor information */
546 gl_string = (const char *) glGetString(GL_VERSION);
547 if (gl_string != NULL) {
549 /* First, parse the generic opengl version. This is supposed not to be convoluted with
550 * driver specific information
552 gl_string_cursor = gl_string;
553 major = atoi(gl_string_cursor);
554 if(major <= 0) {
555 ERR("Invalid opengl major version: %d\n", major);
557 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
558 ++gl_string_cursor;
560 if (*gl_string_cursor++ != '.') {
561 ERR_(d3d_caps)("Invalid opengl version string: %s\n", debugstr_a(gl_string));
563 minor = atoi(gl_string_cursor);
564 TRACE_(d3d_caps)("Found OpenGL version: %d.%d\n", major, minor);
565 gl_info->gl_version = MAKEDWORD_VERSION(major, minor);
567 /* Now parse the driver specific string which we'll report to the app */
568 switch (gl_info->gl_vendor) {
569 case VENDOR_NVIDIA:
570 gl_string_cursor = strstr(gl_string, "NVIDIA");
571 if (!gl_string_cursor) {
572 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
573 break;
576 gl_string_cursor = strstr(gl_string_cursor, " ");
577 if (!gl_string_cursor) {
578 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
579 break;
582 while (*gl_string_cursor == ' ') {
583 ++gl_string_cursor;
586 if (!*gl_string_cursor) {
587 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
588 break;
591 major = atoi(gl_string_cursor);
592 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
593 ++gl_string_cursor;
596 if (*gl_string_cursor++ != '.') {
597 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
598 break;
601 minor = atoi(gl_string_cursor);
602 minor = major*100+minor;
603 major = 10;
605 break;
607 case VENDOR_ATI:
608 major = minor = 0;
609 gl_string_cursor = strchr(gl_string, '-');
610 if (gl_string_cursor) {
611 gl_string_cursor++;
613 /* Check if version number is of the form x.y.z */
614 if ( *gl_string_cursor < '0' || *gl_string_cursor > '9'
615 || *(gl_string_cursor+1) != '.'
616 || *(gl_string_cursor+2) < '0' || *(gl_string_cursor+2) > '9'
617 || *(gl_string_cursor+3) != '.'
618 || *(gl_string_cursor+4) < '0' || *(gl_string_cursor+4) > '9' )
619 /* Mark version number as malformed */
620 gl_string_cursor = 0;
623 if (!gl_string_cursor)
624 WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
625 else {
626 major = *gl_string_cursor - '0';
627 minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
629 break;
631 case VENDOR_INTEL:
632 /* Apple and Mesa version strings look differently, but both provide intel drivers */
633 if(strstr(gl_string, "APPLE")) {
634 /* [0-9]+.[0-9]+ APPLE-[0-9]+.[0.9]+.[0.9]+
635 * We only need the first part, and use the APPLE as identification
636 * "1.2 APPLE-1.4.56"
638 gl_string_cursor = gl_string;
639 major = atoi(gl_string_cursor);
640 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
641 ++gl_string_cursor;
644 if (*gl_string_cursor++ != '.') {
645 ERR_(d3d_caps)("Invalid MacOS-Intel version string: %s\n", debugstr_a(gl_string));
646 break;
649 minor = atoi(gl_string_cursor);
650 break;
653 case VENDOR_MESA:
654 gl_string_cursor = strstr(gl_string, "Mesa");
655 gl_string_cursor = strstr(gl_string_cursor, " ");
656 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
657 if (*gl_string_cursor) {
658 char tmp[16];
659 int cursor = 0;
661 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
662 tmp[cursor++] = *gl_string_cursor;
663 ++gl_string_cursor;
665 tmp[cursor] = 0;
666 major = atoi(tmp);
668 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
669 ++gl_string_cursor;
671 cursor = 0;
672 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
673 tmp[cursor++] = *gl_string_cursor;
674 ++gl_string_cursor;
676 tmp[cursor] = 0;
677 minor = atoi(tmp);
679 break;
681 default:
682 major = 0;
683 minor = 9;
685 gl_info->driver_version = MAKEDWORD_VERSION(major, minor);
686 TRACE_(d3d_caps)("found driver version (%s)->%i.%i->(0x%08x)\n", debugstr_a(gl_string), major, minor, gl_info->driver_version);
687 /* Current Windows drivers have versions like 6.14.... (some older have an earlier version) */
688 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
689 } else {
690 FIXME("OpenGL driver did not return version information\n");
691 gl_info->driver_version = MAKEDWORD_VERSION(0, 0);
692 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
695 TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
698 * Initialize openGL extension related variables
699 * with Default values
701 memset(gl_info->supported, 0, sizeof(gl_info->supported));
702 gl_info->max_buffers = 1;
703 gl_info->max_textures = 1;
704 gl_info->max_texture_stages = 1;
705 gl_info->max_fragment_samplers = 1;
706 gl_info->max_vertex_samplers = 0;
707 gl_info->max_combined_samplers = gl_info->max_fragment_samplers + gl_info->max_vertex_samplers;
708 gl_info->max_sampler_stages = 1;
709 gl_info->ps_arb_version = PS_VERSION_NOT_SUPPORTED;
710 gl_info->ps_arb_max_temps = 0;
711 gl_info->ps_arb_max_instructions = 0;
712 gl_info->vs_arb_version = VS_VERSION_NOT_SUPPORTED;
713 gl_info->vs_arb_max_temps = 0;
714 gl_info->vs_arb_max_instructions = 0;
715 gl_info->vs_nv_version = VS_VERSION_NOT_SUPPORTED;
716 gl_info->vs_ati_version = VS_VERSION_NOT_SUPPORTED;
717 gl_info->vs_glsl_constantsF = 0;
718 gl_info->ps_glsl_constantsF = 0;
719 gl_info->vs_arb_constantsF = 0;
720 gl_info->ps_arb_constantsF = 0;
722 /* Retrieve opengl defaults */
723 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
724 gl_info->max_clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
725 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
727 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
728 gl_info->max_lights = gl_max;
729 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
731 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
732 gl_info->max_texture_size = gl_max;
733 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
735 glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, gl_floatv);
736 gl_info->max_pointsizemin = gl_floatv[0];
737 gl_info->max_pointsize = gl_floatv[1];
738 TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
740 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
741 GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
742 TRACE_(d3d_caps)("GL_Extensions reported:\n");
744 if (NULL == GL_Extensions) {
745 ERR(" GL_Extensions returns NULL\n");
746 } else {
747 gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
749 while (*GL_Extensions != 0x00) {
750 const char *Start;
751 char ThisExtn[256];
752 size_t len;
754 while (isspace(*GL_Extensions)) GL_Extensions++;
755 Start = GL_Extensions;
756 while (!isspace(*GL_Extensions) && *GL_Extensions != 0x00) {
757 GL_Extensions++;
760 len = GL_Extensions - Start;
761 if (len == 0 || len >= sizeof(ThisExtn))
762 continue;
764 memcpy(ThisExtn, Start, len);
765 ThisExtn[len] = '\0';
766 TRACE_(d3d_caps)("- %s\n", ThisExtn);
768 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
769 if (!strcmp(ThisExtn, EXTENSION_MAP[i].extension_string)) {
770 TRACE_(d3d_caps)(" FOUND: %s support\n", EXTENSION_MAP[i].extension_string);
771 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
772 break;
777 LEAVE_GL();
779 /* Now work out what GL support this card really has */
780 #define USE_GL_FUNC(type, pfn, ext, replace) { \
781 DWORD ver = ver_for_ext(ext); \
782 if(gl_info->supported[ext]) gl_info->pfn = (type) pwglGetProcAddress(#pfn); \
783 else if(ver && ver <= gl_info->gl_version) gl_info->pfn = (type) pwglGetProcAddress(#replace); \
784 else gl_info->pfn = NULL; \
786 GL_EXT_FUNCS_GEN;
787 #undef USE_GL_FUNC
789 #define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type) pwglGetProcAddress(#pfn);
790 WGL_EXT_FUNCS_GEN;
791 #undef USE_GL_FUNC
793 ENTER_GL();
794 /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
795 * loading the functions, otherwise the code above will load the extension entry points instead of the
796 * core functions, which may not work
798 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
799 if (gl_info->supported[EXTENSION_MAP[i].extension] == FALSE &&
800 EXTENSION_MAP[i].version <= gl_info->gl_version && EXTENSION_MAP[i].version) {
801 TRACE_(d3d_caps)(" GL CORE: %s support\n", EXTENSION_MAP[i].extension_string);
802 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
806 if (gl_info->supported[APPLE_FENCE]) {
807 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
808 * The apple extension interacts with some other apple exts. Disable the NV
809 * extension if the apple one is support to prevent confusion in other parts
810 * of the code
812 gl_info->supported[NV_FENCE] = FALSE;
814 if (gl_info->supported[APPLE_FLOAT_PIXELS]) {
815 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
817 * The enums are the same:
818 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881A
819 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881B
820 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
821 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
822 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140B
824 if(!gl_info->supported[ARB_TEXTURE_FLOAT]) {
825 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels\n");
826 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
828 if(!gl_info->supported[ARB_HALF_FLOAT_PIXEL]) {
829 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels\n");
830 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
833 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) {
834 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
835 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
837 if (gl_info->supported[NV_TEXTURE_SHADER2]) {
838 if(gl_info->supported[NV_REGISTER_COMBINERS]) {
839 /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
840 * are supported. The nv extensions provide the same functionality as the
841 * ATI one, and a bit more(signed pixelformats)
843 gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
846 if (gl_info->supported[ARB_DRAW_BUFFERS]) {
847 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
848 gl_info->max_buffers = gl_max;
849 TRACE_(d3d_caps)("Max draw buffers: %u\n", gl_max);
851 if (gl_info->supported[ARB_MULTITEXTURE]) {
852 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
853 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
854 TRACE_(d3d_caps)("Max textures: %d\n", gl_info->max_textures);
856 if (gl_info->supported[NV_REGISTER_COMBINERS]) {
857 GLint tmp;
858 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &tmp);
859 gl_info->max_texture_stages = min(MAX_TEXTURES, tmp);
860 } else {
861 gl_info->max_texture_stages = min(MAX_TEXTURES, gl_max);
863 TRACE_(d3d_caps)("Max texture stages: %d\n", gl_info->max_texture_stages);
865 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
866 GLint tmp;
867 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
868 gl_info->max_fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
869 } else {
870 gl_info->max_fragment_samplers = max(gl_info->max_fragment_samplers, gl_max);
872 TRACE_(d3d_caps)("Max fragment samplers: %d\n", gl_info->max_fragment_samplers);
874 if (gl_info->supported[ARB_VERTEX_SHADER]) {
875 GLint tmp;
876 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
877 gl_info->max_vertex_samplers = tmp;
878 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
879 gl_info->max_combined_samplers = tmp;
881 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
882 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
883 * an issue because then the sampler setup only depends on the two shaders. If a pixel
884 * shader is used with fixed function vertex processing we're fine too because fixed function
885 * vertex processing doesn't use any samplers. If fixed function fragment processing is
886 * used we have to make sure that all vertex sampler setups are valid together with all
887 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
888 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
889 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
890 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
891 * a fixed function pipeline anymore.
893 * So this is just a check to check that our assumption holds true. If not, write a warning
894 * and reduce the number of vertex samplers or probably disable vertex texture fetch.
896 if(gl_info->max_vertex_samplers && gl_info->max_combined_samplers < 12 &&
897 MAX_TEXTURES + gl_info->max_vertex_samplers > gl_info->max_combined_samplers) {
898 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers\n",
899 gl_info->max_vertex_samplers, gl_info->max_combined_samplers);
900 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers\n");
901 if( gl_info->max_combined_samplers > MAX_TEXTURES )
902 gl_info->max_vertex_samplers =
903 gl_info->max_combined_samplers - MAX_TEXTURES;
904 else
905 gl_info->max_vertex_samplers = 0;
907 } else {
908 gl_info->max_combined_samplers = gl_info->max_fragment_samplers;
910 TRACE_(d3d_caps)("Max vertex samplers: %u\n", gl_info->max_vertex_samplers);
911 TRACE_(d3d_caps)("Max combined samplers: %u\n", gl_info->max_combined_samplers);
913 if (gl_info->supported[ARB_VERTEX_BLEND]) {
914 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
915 gl_info->max_blends = gl_max;
916 TRACE_(d3d_caps)("Max blends: %u\n", gl_info->max_blends);
918 if (gl_info->supported[EXT_TEXTURE3D]) {
919 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
920 gl_info->max_texture3d_size = gl_max;
921 TRACE_(d3d_caps)("Max texture3D size: %d\n", gl_info->max_texture3d_size);
923 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC]) {
924 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
925 gl_info->max_anisotropy = gl_max;
926 TRACE_(d3d_caps)("Max anisotropy: %d\n", gl_info->max_anisotropy);
928 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
929 gl_info->ps_arb_version = PS_VERSION_11;
930 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
931 gl_info->ps_arb_constantsF = gl_max;
932 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d\n", gl_info->ps_arb_constantsF);
933 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
934 gl_info->ps_arb_max_temps = gl_max;
935 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d\n", gl_info->ps_arb_max_temps);
936 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
937 gl_info->ps_arb_max_instructions = gl_max;
938 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d\n", gl_info->ps_arb_max_instructions);
940 if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
941 gl_info->vs_arb_version = VS_VERSION_11;
942 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
943 gl_info->vs_arb_constantsF = gl_max;
944 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d\n", gl_info->vs_arb_constantsF);
945 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
946 gl_info->vs_arb_max_temps = gl_max;
947 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d\n", gl_info->vs_arb_max_temps);
948 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
949 gl_info->vs_arb_max_instructions = gl_max;
950 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d\n", gl_info->vs_arb_max_instructions);
952 gl_info->arb_vs_offset_limit = test_arb_vs_offset_limit(gl_info);
954 if (gl_info->supported[ARB_VERTEX_SHADER]) {
955 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
956 gl_info->vs_glsl_constantsF = gl_max / 4;
957 TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u\n", gl_info->vs_glsl_constantsF);
959 if (gl_info->supported[ARB_FRAGMENT_SHADER]) {
960 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
961 gl_info->ps_glsl_constantsF = gl_max / 4;
962 TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u\n", gl_info->ps_glsl_constantsF);
963 glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
964 gl_info->max_glsl_varyings = gl_max;
965 TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings)\n", gl_max, gl_max / 4);
967 if (gl_info->supported[EXT_VERTEX_SHADER]) {
968 gl_info->vs_ati_version = VS_VERSION_11;
970 if (gl_info->supported[NV_VERTEX_PROGRAM3]) {
971 gl_info->vs_nv_version = VS_VERSION_30;
972 } else if (gl_info->supported[NV_VERTEX_PROGRAM2]) {
973 gl_info->vs_nv_version = VS_VERSION_20;
974 } else if (gl_info->supported[NV_VERTEX_PROGRAM1_1]) {
975 gl_info->vs_nv_version = VS_VERSION_11;
976 } else if (gl_info->supported[NV_VERTEX_PROGRAM]) {
977 gl_info->vs_nv_version = VS_VERSION_10;
979 if (gl_info->supported[NV_FRAGMENT_PROGRAM2]) {
980 gl_info->ps_nv_version = PS_VERSION_30;
981 } else if (gl_info->supported[NV_FRAGMENT_PROGRAM]) {
982 gl_info->ps_nv_version = PS_VERSION_20;
984 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT]) {
985 glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->max_shininess);
986 } else {
987 gl_info->max_shininess = 128.0;
989 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO]) {
990 /* If we have full NP2 texture support, disable GL_ARB_texture_rectangle because we will never use it.
991 * This saves a few redundant glDisable calls
993 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
995 if(gl_info->supported[ATI_FRAGMENT_SHADER]) {
996 /* Disable NV_register_combiners and fragment shader if this is supported.
997 * generally the NV extensions are preferred over the ATI ones, and this
998 * extension is disabled if register_combiners and texture_shader2 are both
999 * supported. So we reach this place only if we have incomplete NV dxlevel 8
1000 * fragment processing support
1002 gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
1003 gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
1004 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
1005 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
1006 gl_info->supported[NV_TEXTURE_SHADER3] = FALSE;
1008 if(gl_info->supported[NV_HALF_FLOAT]) {
1009 /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float */
1010 gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE;
1012 if(gl_info->supported[ARB_POINT_SPRITE]) {
1013 gl_info->max_point_sprite_units = gl_info->max_textures;
1014 } else {
1015 gl_info->max_point_sprite_units = 0;
1018 checkGLcall("extension detection\n");
1020 /* In some cases the number of texture stages can be larger than the number
1021 * of samplers. The GF4 for example can use only 2 samplers (no fragment
1022 * shaders), but 8 texture stages (register combiners). */
1023 gl_info->max_sampler_stages = max(gl_info->max_fragment_samplers, gl_info->max_texture_stages);
1025 /* We can only use ORM_FBO when the hardware supports it. */
1026 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && !gl_info->supported[EXT_FRAMEBUFFER_OBJECT]) {
1027 WARN_(d3d_caps)("GL_EXT_framebuffer_object not supported, falling back to backbuffer offscreen rendering mode.\n");
1028 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
1031 /* MRTs are currently only supported when FBOs are used. */
1032 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) {
1033 gl_info->max_buffers = 1;
1036 /* Below is a list of Nvidia and ATI GPUs. Both vendors have dozens of different GPUs with roughly the same
1037 * features. In most cases GPUs from a certain family differ in clockspeeds, the amount of video memory and
1038 * in case of the latest videocards in the number of pixel/vertex pipelines.
1040 * A Direct3D device object contains the PCI id (vendor + device) of the videocard which is used for
1041 * rendering. Various games use this information to get a rough estimation of the features of the card
1042 * and some might use it for enabling 3d effects only on certain types of videocards. In some cases
1043 * games might even use it to work around bugs which happen on certain videocards/driver combinations.
1044 * The problem is that OpenGL only exposes a rendering string containing the name of the videocard and
1045 * not the PCI id.
1047 * Various games depend on the PCI id, so somehow we need to provide one. A simple option is to parse
1048 * the renderer string and translate this to the right PCI id. This is a lot of work because there are more
1049 * than 200 GPUs just for Nvidia. Various cards share the same renderer string, so the amount of code might
1050 * be 'small' but there are quite a number of exceptions which would make this a pain to maintain.
1051 * Another way would be to query the PCI id from the operating system (assuming this is the videocard which
1052 * is used for rendering which is not always the case). This would work but it is not very portable. Second
1053 * it would not work well in, let's say, a remote X situation in which the amount of 3d features which can be used
1054 * is limited.
1056 * As said most games only use the PCI id to get an indication of the capabilities of the card.
1057 * It doesn't really matter if the given id is the correct one if we return the id of a card with
1058 * similar 3d features.
1060 * The code below checks the OpenGL capabilities of a videocard and matches that to a certain level of
1061 * Direct3D functionality. Once a card passes the Direct3D9 check, we know that the card (in case of Nvidia)
1062 * is at least a GeforceFX. To give a better estimate we do a basic check on the renderer string but if that
1063 * won't pass we return a default card. This way is better than maintaining a full card database as even
1064 * without a full database we can return a card with similar features. Second the size of the database
1065 * can be made quite small because when you know what type of 3d functionality a card has, you know to which
1066 * GPU family the GPU must belong. Because of this you only have to check a small part of the renderer string
1067 * to distinguishes between different models from that family.
1069 * The code also selects a default amount of video memory which we will use for an estimation of the amount
1070 * of free texture memory. In case of real D3D the amount of texture memory includes video memory and system
1071 * memory (to be specific AGP memory or in case of PCIE TurboCache/HyperMemory). We don't know how much
1072 * system memory can be addressed by the system but we can make a reasonable estimation about the amount of
1073 * video memory. If the value is slightly wrong it doesn't matter as we didn't include AGP-like memory which
1074 * makes the amount of addressable memory higher and second OpenGL isn't that critical it moves to system
1075 * memory behind our backs if really needed.
1076 * Note that the amount of video memory can be overruled using a registry setting.
1078 switch (gl_info->gl_vendor) {
1079 case VENDOR_NVIDIA:
1080 /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1081 * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1083 if(WINE_D3D9_CAPABLE(gl_info) && (gl_info->vs_nv_version == VS_VERSION_30)) {
1084 /* Geforce 200 - highend */
1085 if(strstr(gl_info->gl_renderer, "GTX 280") ||
1086 strstr(gl_info->gl_renderer, "GTX 285") ||
1087 strstr(gl_info->gl_renderer, "GTX 295"))
1089 gl_info->gl_card = CARD_NVIDIA_GEFORCE_GTX280;
1090 vidmem = 1024;
1092 /* Geforce 200 - midend high */
1093 if(strstr(gl_info->gl_renderer, "GTX 275")) {
1094 gl_info->gl_card = CARD_NVIDIA_GEFORCE_GTX275;
1095 vidmem = 896;
1097 /* Geforce 200 - midend */
1098 if(strstr(gl_info->gl_renderer, "GTX 260")) {
1099 gl_info->gl_card = CARD_NVIDIA_GEFORCE_GTX260;
1100 vidmem = 1024;
1102 /* Geforce9 - highend / Geforce 200 - midend (GTS 150/250 are based on the same core) */
1103 else if(strstr(gl_info->gl_renderer, "9800") ||
1104 strstr(gl_info->gl_renderer, "GTS 150") ||
1105 strstr(gl_info->gl_renderer, "GTS 250"))
1107 gl_info->gl_card = CARD_NVIDIA_GEFORCE_9800GT;
1108 vidmem = 512;
1110 /* Geforce9 - midend */
1111 else if(strstr(gl_info->gl_renderer, "9600")) {
1112 gl_info->gl_card = CARD_NVIDIA_GEFORCE_9600GT;
1113 vidmem = 384; /* The 9600GSO has 384MB, the 9600GT has 512-1024MB */
1115 /* Geforce9 - midend low / Geforce 200 - low*/
1116 else if(strstr(gl_info->gl_renderer, "9500") ||
1117 strstr(gl_info->gl_renderer, "GT 120") ||
1118 strstr(gl_info->gl_renderer, "GT 130"))
1120 gl_info->gl_card = CARD_NVIDIA_GEFORCE_9500GT;
1121 vidmem = 256; /* The 9500GT has 256-1024MB */
1123 /* Geforce9 - lowend */
1124 else if(strstr(gl_info->gl_renderer, "9400")) {
1125 gl_info->gl_card = CARD_NVIDIA_GEFORCE_9400GT;
1126 vidmem = 256; /* The 9400GT has 256-1024MB */
1128 /* Geforce9 - lowend low */
1129 else if(strstr(gl_info->gl_renderer, "9100") ||
1130 strstr(gl_info->gl_renderer, "9200") ||
1131 strstr(gl_info->gl_renderer, "9300") ||
1132 strstr(gl_info->gl_renderer, "G 100"))
1134 gl_info->gl_card = CARD_NVIDIA_GEFORCE_9200;
1135 vidmem = 256; /* The 9100-9300 cards have 256MB */
1137 /* Geforce8 - highend */
1138 else if (strstr(gl_info->gl_renderer, "8800")) {
1139 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8800GTS;
1140 vidmem = 320; /* The 8800GTS uses 320MB, a 8800GTX can have 768MB */
1142 /* Geforce8 - midend mobile */
1143 else if(strstr(gl_info->gl_renderer, "8600 M")) {
1144 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600MGT;
1145 vidmem = 512;
1147 /* Geforce8 - midend */
1148 else if(strstr(gl_info->gl_renderer, "8600") ||
1149 strstr(gl_info->gl_renderer, "8700"))
1151 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600GT;
1152 vidmem = 256;
1154 /* Geforce8 - lowend */
1155 else if(strstr(gl_info->gl_renderer, "8300") ||
1156 strstr(gl_info->gl_renderer, "8400") ||
1157 strstr(gl_info->gl_renderer, "8500"))
1159 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8300GS;
1160 vidmem = 128; /* 128-256MB for a 8300, 256-512MB for a 8400 */
1162 /* Geforce7 - highend */
1163 else if(strstr(gl_info->gl_renderer, "7800") ||
1164 strstr(gl_info->gl_renderer, "7900") ||
1165 strstr(gl_info->gl_renderer, "7950") ||
1166 strstr(gl_info->gl_renderer, "Quadro FX 4") ||
1167 strstr(gl_info->gl_renderer, "Quadro FX 5"))
1169 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7800GT;
1170 vidmem = 256; /* A 7800GT uses 256MB while highend 7900 cards can use 512MB */
1172 /* Geforce7 midend */
1173 else if(strstr(gl_info->gl_renderer, "7600") ||
1174 strstr(gl_info->gl_renderer, "7700")) {
1175 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7600;
1176 vidmem = 256; /* The 7600 uses 256-512MB */
1177 /* Geforce7 lower medium */
1178 } else if(strstr(gl_info->gl_renderer, "7400")) {
1179 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7400;
1180 vidmem = 256; /* The 7400 uses 256-512MB */
1182 /* Geforce7 lowend */
1183 else if(strstr(gl_info->gl_renderer, "7300")) {
1184 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7300;
1185 vidmem = 256; /* Mac Pros with this card have 256 MB */
1187 /* Geforce6 highend */
1188 else if(strstr(gl_info->gl_renderer, "6800"))
1190 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6800;
1191 vidmem = 128; /* The 6800 uses 128-256MB, the 7600 uses 256-512MB */
1193 /* Geforce6 - midend */
1194 else if(strstr(gl_info->gl_renderer, "6600") ||
1195 strstr(gl_info->gl_renderer, "6610") ||
1196 strstr(gl_info->gl_renderer, "6700"))
1198 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6600GT;
1199 vidmem = 128; /* A 6600GT has 128-256MB */
1201 /* Geforce6/7 lowend */
1202 else {
1203 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
1204 vidmem = 64; /* */
1206 } else if(WINE_D3D9_CAPABLE(gl_info)) {
1207 /* GeforceFX - highend */
1208 if (strstr(gl_info->gl_renderer, "5800") ||
1209 strstr(gl_info->gl_renderer, "5900") ||
1210 strstr(gl_info->gl_renderer, "5950") ||
1211 strstr(gl_info->gl_renderer, "Quadro FX"))
1213 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5800;
1214 vidmem = 256; /* 5800-5900 cards use 256MB */
1216 /* GeforceFX - midend */
1217 else if(strstr(gl_info->gl_renderer, "5600") ||
1218 strstr(gl_info->gl_renderer, "5650") ||
1219 strstr(gl_info->gl_renderer, "5700") ||
1220 strstr(gl_info->gl_renderer, "5750"))
1222 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1223 vidmem = 128; /* A 5600 uses 128-256MB */
1225 /* GeforceFX - lowend */
1226 else {
1227 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1228 vidmem = 64; /* Normal FX5200 cards use 64-256MB; laptop (non-standard) can have less */
1230 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1231 if (strstr(gl_info->gl_renderer, "GeForce4 Ti") || strstr(gl_info->gl_renderer, "Quadro4")) {
1232 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1233 vidmem = 64; /* Geforce4 Ti cards have 64-128MB */
1235 else {
1236 gl_info->gl_card = CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1237 vidmem = 64; /* Geforce3 cards have 64-128MB */
1239 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1240 if (strstr(gl_info->gl_renderer, "GeForce4 MX")) {
1241 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1242 vidmem = 64; /* Most Geforce4MX GPUs have at least 64MB of memory, some early models had 32MB but most have 64MB or even 128MB */
1244 else if(strstr(gl_info->gl_renderer, "GeForce2 MX") || strstr(gl_info->gl_renderer, "Quadro2 MXR")) {
1245 gl_info->gl_card = CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1246 vidmem = 32; /* Geforce2MX GPUs have 32-64MB of video memory */
1248 else if(strstr(gl_info->gl_renderer, "GeForce2") || strstr(gl_info->gl_renderer, "Quadro2")) {
1249 gl_info->gl_card = CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1250 vidmem = 32; /* Geforce2 GPUs have 32-64MB of video memory */
1252 else {
1253 gl_info->gl_card = CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1254 vidmem = 32; /* Most Geforce1 cards have 32MB, there are also some rare 16 and 64MB (Dell) models */
1256 } else {
1257 if (strstr(gl_info->gl_renderer, "TNT2")) {
1258 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1259 vidmem = 32; /* Most TNT2 boards have 32MB, though there are 16MB boards too */
1261 else {
1262 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1263 vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
1266 break;
1267 case VENDOR_ATI:
1268 /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx
1270 * beware: renderer string do not match exact card model,
1271 * eg HD 4800 is returned for multiple card, even for RV790 based one
1273 if(WINE_D3D9_CAPABLE(gl_info)) {
1274 /* Radeon R7xx HD4800 - highend */
1275 if (strstr(gl_info->gl_renderer, "HD 4800") || /* Radeon RV7xx HD48xx generic renderer string */
1276 strstr(gl_info->gl_renderer, "HD 4830") || /* Radeon RV770 */
1277 strstr(gl_info->gl_renderer, "HD 4850") || /* Radeon RV770 */
1278 strstr(gl_info->gl_renderer, "HD 4870") || /* Radeon RV770 */
1279 strstr(gl_info->gl_renderer, "HD 4890")) /* Radeon RV790 */
1281 gl_info->gl_card = CARD_ATI_RADEON_HD4800;
1282 vidmem = 512; /* note: HD4890 cards use 1024MB */
1284 /* Radeon R740 HD4700 - midend */
1285 else if (strstr(gl_info->gl_renderer, "HD 4700") || /* Radeon RV770 */
1286 strstr(gl_info->gl_renderer, "HD 4770")) /* Radeon RV740 */
1288 gl_info->gl_card = CARD_ATI_RADEON_HD4700;
1289 vidmem = 512;
1291 /* Radeon R730 HD4600 - midend */
1292 else if (strstr(gl_info->gl_renderer, "HD 4600") || /* Radeon RV730 */
1293 strstr(gl_info->gl_renderer, "HD 4650") || /* Radeon RV730 */
1294 strstr(gl_info->gl_renderer, "HD 4670")) /* Radeon RV730 */
1296 gl_info->gl_card = CARD_ATI_RADEON_HD4600;
1297 vidmem = 512;
1299 /* Radeon R710 HD4500/HD4350 - lowend */
1300 else if (strstr(gl_info->gl_renderer, "HD 4350") || /* Radeon RV710 */
1301 strstr(gl_info->gl_renderer, "HD 4550")) /* Radeon RV710 */
1303 gl_info->gl_card = CARD_ATI_RADEON_HD4350;
1304 vidmem = 256;
1306 /* Radeon R6xx HD2900/HD3800 - highend */
1307 else if (strstr(gl_info->gl_renderer, "HD 2900") ||
1308 strstr(gl_info->gl_renderer, "HD 3870") ||
1309 strstr(gl_info->gl_renderer, "HD 3850"))
1311 gl_info->gl_card = CARD_ATI_RADEON_HD2900;
1312 vidmem = 512; /* HD2900/HD3800 uses 256-1024MB */
1314 /* Radeon R6xx HD2600/HD3600 - midend; HD3830 is China-only midend */
1315 else if (strstr(gl_info->gl_renderer, "HD 2600") ||
1316 strstr(gl_info->gl_renderer, "HD 3830") ||
1317 strstr(gl_info->gl_renderer, "HD 3690") ||
1318 strstr(gl_info->gl_renderer, "HD 3650"))
1320 gl_info->gl_card = CARD_ATI_RADEON_HD2600;
1321 vidmem = 256; /* HD2600/HD3600 uses 256-512MB */
1323 /* Radeon R6xx HD2300/HD2400/HD3400 - lowend */
1324 else if (strstr(gl_info->gl_renderer, "HD 2300") ||
1325 strstr(gl_info->gl_renderer, "HD 2400") ||
1326 strstr(gl_info->gl_renderer, "HD 3470") ||
1327 strstr(gl_info->gl_renderer, "HD 3450") ||
1328 strstr(gl_info->gl_renderer, "HD 3430") ||
1329 strstr(gl_info->gl_renderer, "HD 3400"))
1331 gl_info->gl_card = CARD_ATI_RADEON_HD2300;
1332 vidmem = 128; /* HD2300 uses at least 128MB, HD2400 uses 256MB */
1334 /* Radeon R6xx/R7xx integrated */
1335 else if (strstr(gl_info->gl_renderer, "HD 3100") ||
1336 strstr(gl_info->gl_renderer, "HD 3200") ||
1337 strstr(gl_info->gl_renderer, "HD 3300"))
1339 gl_info->gl_card = CARD_ATI_RADEON_HD3200;
1340 vidmem = 128; /* 128MB */
1342 /* Radeon R5xx */
1343 else if (strstr(gl_info->gl_renderer, "X1600") ||
1344 strstr(gl_info->gl_renderer, "X1650") ||
1345 strstr(gl_info->gl_renderer, "X1800") ||
1346 strstr(gl_info->gl_renderer, "X1900") ||
1347 strstr(gl_info->gl_renderer, "X1950"))
1349 gl_info->gl_card = CARD_ATI_RADEON_X1600;
1350 vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
1352 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
1353 else if(strstr(gl_info->gl_renderer, "X700") ||
1354 strstr(gl_info->gl_renderer, "X800") ||
1355 strstr(gl_info->gl_renderer, "X850") ||
1356 strstr(gl_info->gl_renderer, "X1300") ||
1357 strstr(gl_info->gl_renderer, "X1400") ||
1358 strstr(gl_info->gl_renderer, "X1450") ||
1359 strstr(gl_info->gl_renderer, "X1550"))
1361 gl_info->gl_card = CARD_ATI_RADEON_X700;
1362 vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
1364 /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400MHz */
1365 else if(strstr(gl_info->gl_renderer, "Radeon Xpress"))
1367 gl_info->gl_card = CARD_ATI_RADEON_XPRESS_200M;
1368 vidmem = 64; /* Shared RAM, BIOS configurable, 64-256M */
1370 /* Radeon R3xx */
1371 else {
1372 gl_info->gl_card = CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
1373 vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
1375 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1376 gl_info->gl_card = CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
1377 vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
1378 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1379 gl_info->gl_card = CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
1380 vidmem = 32; /* There are models with up to 64MB */
1381 } else {
1382 gl_info->gl_card = CARD_ATI_RAGE_128PRO;
1383 vidmem = 16; /* There are 16-32MB models */
1385 break;
1386 case VENDOR_INTEL:
1387 if (strstr(gl_info->gl_renderer, "GMA 950") ||
1388 strstr(gl_info->gl_renderer, "945GM")) {
1389 /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */
1390 gl_info->gl_card = CARD_INTEL_I945GM;
1391 vidmem = 64;
1392 } else if (strstr(gl_info->gl_renderer, "915GM")) {
1393 gl_info->gl_card = CARD_INTEL_I915GM;
1394 } else if (strstr(gl_info->gl_renderer, "915G")) {
1395 gl_info->gl_card = CARD_INTEL_I915G;
1396 } else if (strstr(gl_info->gl_renderer, "865G")) {
1397 gl_info->gl_card = CARD_INTEL_I865G;
1398 } else if (strstr(gl_info->gl_renderer, "855G")) {
1399 gl_info->gl_card = CARD_INTEL_I855G;
1400 } else if (strstr(gl_info->gl_renderer, "830G")) {
1401 gl_info->gl_card = CARD_INTEL_I830G;
1402 } else {
1403 gl_info->gl_card = CARD_INTEL_I915G;
1405 break;
1406 case VENDOR_MESA:
1407 case VENDOR_WINE:
1408 default:
1409 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice
1410 * for Nvidia was because the hardware and drivers they make are of good quality. This makes
1411 * them a good generic choice.
1413 gl_info->gl_vendor = VENDOR_NVIDIA;
1414 if(WINE_D3D9_CAPABLE(gl_info))
1415 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1416 else if(WINE_D3D8_CAPABLE(gl_info))
1417 gl_info->gl_card = CARD_NVIDIA_GEFORCE3;
1418 else if(WINE_D3D7_CAPABLE(gl_info))
1419 gl_info->gl_card = CARD_NVIDIA_GEFORCE;
1420 else if(WINE_D3D6_CAPABLE(gl_info))
1421 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT;
1422 else
1423 gl_info->gl_card = CARD_NVIDIA_RIVA_128;
1425 TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card);
1427 /* If we have an estimate use it, else default to 64MB; */
1428 if(vidmem)
1429 gl_info->vidmem = vidmem*1024*1024; /* convert from MBs to bytes */
1430 else
1431 gl_info->vidmem = WINE_DEFAULT_VIDMEM;
1433 /* Load all the lookup tables */
1434 for (i = 0; i < MAX_LOOKUPS; i++) {
1435 stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
1438 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
1439 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
1440 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1441 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1442 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1443 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1444 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
1445 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
1446 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
1447 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
1449 magLookup[WINED3DTEXF_NONE - WINED3DTEXF_NONE] = GL_NEAREST;
1450 magLookup[WINED3DTEXF_POINT - WINED3DTEXF_NONE] = GL_NEAREST;
1451 magLookup[WINED3DTEXF_LINEAR - WINED3DTEXF_NONE] = GL_LINEAR;
1452 magLookup[WINED3DTEXF_ANISOTROPIC - WINED3DTEXF_NONE] =
1453 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR : GL_NEAREST;
1456 minMipLookup[WINED3DTEXF_NONE].mip[WINED3DTEXF_NONE] = GL_LINEAR;
1457 minMipLookup[WINED3DTEXF_NONE].mip[WINED3DTEXF_POINT] = GL_LINEAR;
1458 minMipLookup[WINED3DTEXF_NONE].mip[WINED3DTEXF_LINEAR] = GL_LINEAR;
1459 minMipLookup[WINED3DTEXF_POINT].mip[WINED3DTEXF_NONE] = GL_NEAREST;
1460 minMipLookup[WINED3DTEXF_POINT].mip[WINED3DTEXF_POINT] = GL_NEAREST_MIPMAP_NEAREST;
1461 minMipLookup[WINED3DTEXF_POINT].mip[WINED3DTEXF_LINEAR] = GL_NEAREST_MIPMAP_LINEAR;
1462 minMipLookup[WINED3DTEXF_LINEAR].mip[WINED3DTEXF_NONE] = GL_LINEAR;
1463 minMipLookup[WINED3DTEXF_LINEAR].mip[WINED3DTEXF_POINT] = GL_LINEAR_MIPMAP_NEAREST;
1464 minMipLookup[WINED3DTEXF_LINEAR].mip[WINED3DTEXF_LINEAR] = GL_LINEAR_MIPMAP_LINEAR;
1465 minMipLookup[WINED3DTEXF_ANISOTROPIC].mip[WINED3DTEXF_NONE]
1466 = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1467 minMipLookup[WINED3DTEXF_ANISOTROPIC].mip[WINED3DTEXF_POINT]
1468 = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR;
1469 minMipLookup[WINED3DTEXF_ANISOTROPIC].mip[WINED3DTEXF_LINEAR]
1470 = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1472 /* TODO: config lookups */
1474 /* Make sure there's an active HDC else the WGL extensions will fail */
1475 hdc = pwglGetCurrentDC();
1476 if (hdc) {
1477 /* Not all GL drivers might offer WGL extensions e.g. VirtualBox */
1478 if(GL_EXTCALL(wglGetExtensionsStringARB))
1479 WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc));
1481 if (NULL == WGL_Extensions) {
1482 ERR(" WGL_Extensions returns NULL\n");
1483 } else {
1484 TRACE_(d3d_caps)("WGL_Extensions reported:\n");
1485 while (*WGL_Extensions != 0x00) {
1486 const char *Start;
1487 char ThisExtn[256];
1488 size_t len;
1490 while (isspace(*WGL_Extensions)) WGL_Extensions++;
1491 Start = WGL_Extensions;
1492 while (!isspace(*WGL_Extensions) && *WGL_Extensions != 0x00) {
1493 WGL_Extensions++;
1496 len = WGL_Extensions - Start;
1497 if (len == 0 || len >= sizeof(ThisExtn))
1498 continue;
1500 memcpy(ThisExtn, Start, len);
1501 ThisExtn[len] = '\0';
1502 TRACE_(d3d_caps)("- %s\n", ThisExtn);
1504 if (!strcmp(ThisExtn, "WGL_ARB_pbuffer")) {
1505 gl_info->supported[WGL_ARB_PBUFFER] = TRUE;
1506 TRACE_(d3d_caps)("FOUND: WGL_ARB_pbuffer support\n");
1508 if (!strcmp(ThisExtn, "WGL_ARB_pixel_format")) {
1509 gl_info->supported[WGL_ARB_PIXEL_FORMAT] = TRUE;
1510 TRACE_(d3d_caps)("FOUND: WGL_ARB_pixel_format support\n");
1512 if (!strcmp(ThisExtn, "WGL_WINE_pixel_format_passthrough")) {
1513 gl_info->supported[WGL_WINE_PIXEL_FORMAT_PASSTHROUGH] = TRUE;
1514 TRACE_(d3d_caps)("FOUND: WGL_WINE_pixel_format_passthrough support\n");
1519 LEAVE_GL();
1521 return return_value;
1524 /**********************************************************
1525 * IWineD3D implementation follows
1526 **********************************************************/
1528 static UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
1529 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1531 TRACE_(d3d_caps)("(%p): Reporting %u adapters\n", This, This->adapter_count);
1533 return This->adapter_count;
1536 static HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
1537 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1538 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
1539 return WINED3D_OK;
1542 static HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
1543 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1545 TRACE_(d3d_caps)("(%p)->(%d)\n", This, Adapter);
1547 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
1548 return NULL;
1551 return MonitorFromPoint(This->adapters[Adapter].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
1554 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
1555 of the same bpp but different resolutions */
1557 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1558 static UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
1559 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1560 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
1562 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1563 return 0;
1566 /* TODO: Store modes per adapter and read it from the adapter structure */
1567 if (Adapter == 0) { /* Display */
1568 unsigned int i = 0;
1569 unsigned int j = 0;
1570 DEVMODEW mode;
1572 memset(&mode, 0, sizeof(mode));
1573 mode.dmSize = sizeof(mode);
1575 while (EnumDisplaySettingsExW(NULL, j, &mode, 0))
1577 ++j;
1578 switch (Format)
1580 case WINED3DFMT_UNKNOWN:
1581 /* This is for D3D8, do not enumerate P8 here */
1582 if (mode.dmBitsPerPel == 32 || mode.dmBitsPerPel == 16) ++i;
1583 break;
1585 case WINED3DFMT_X8R8G8B8:
1586 if (mode.dmBitsPerPel == 32) ++i;
1587 break;
1589 case WINED3DFMT_R5G6B5:
1590 if (mode.dmBitsPerPel == 16) ++i;
1591 break;
1593 case WINED3DFMT_P8:
1594 if (mode.dmBitsPerPel == 8) ++i;
1595 break;
1597 default:
1598 /* Skip other modes as they do not match the requested format */
1599 break;
1603 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
1604 return i;
1605 } else {
1606 FIXME_(d3d_caps)("Adapter not primary display\n");
1608 return 0;
1611 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1612 static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, WINED3DDISPLAYMODE* pMode) {
1613 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1614 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
1616 /* Validate the parameters as much as possible */
1617 if (NULL == pMode ||
1618 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
1619 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
1620 return WINED3DERR_INVALIDCALL;
1623 /* TODO: Store modes per adapter and read it from the adapter structure */
1624 if (Adapter == 0)
1626 DEVMODEW DevModeW;
1627 int ModeIdx = 0;
1628 UINT i = 0;
1629 int j = 0;
1631 ZeroMemory(&DevModeW, sizeof(DevModeW));
1632 DevModeW.dmSize = sizeof(DevModeW);
1634 /* If we are filtering to a specific format (D3D9), then need to skip
1635 all unrelated modes, but if mode is irrelevant (D3D8), then we can
1636 just count through the ones with valid bit depths */
1637 while ((i<=Mode) && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0)) {
1638 switch (Format)
1640 case WINED3DFMT_UNKNOWN:
1641 /* This is D3D8. Do not enumerate P8 here */
1642 if (DevModeW.dmBitsPerPel == 32 ||
1643 DevModeW.dmBitsPerPel == 16) i++;
1644 break;
1645 case WINED3DFMT_X8R8G8B8:
1646 if (DevModeW.dmBitsPerPel == 32) i++;
1647 break;
1648 case WINED3DFMT_R5G6B5:
1649 if (DevModeW.dmBitsPerPel == 16) i++;
1650 break;
1651 case WINED3DFMT_P8:
1652 if (DevModeW.dmBitsPerPel == 8) i++;
1653 break;
1654 default:
1655 /* Modes that don't match what we support can get an early-out */
1656 TRACE_(d3d_caps)("Searching for %s, returning D3DERR_INVALIDCALL\n", debug_d3dformat(Format));
1657 return WINED3DERR_INVALIDCALL;
1661 if (i == 0) {
1662 TRACE_(d3d_caps)("No modes found for format (%x - %s)\n", Format, debug_d3dformat(Format));
1663 return WINED3DERR_INVALIDCALL;
1665 ModeIdx = j - 1;
1667 /* Now get the display mode via the calculated index */
1668 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0)) {
1669 pMode->Width = DevModeW.dmPelsWidth;
1670 pMode->Height = DevModeW.dmPelsHeight;
1671 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1672 if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
1673 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1675 if (Format == WINED3DFMT_UNKNOWN) {
1676 pMode->Format = pixelformat_for_depth(DevModeW.dmBitsPerPel);
1677 } else {
1678 pMode->Format = Format;
1680 } else {
1681 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
1682 return WINED3DERR_INVALIDCALL;
1685 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
1686 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format),
1687 DevModeW.dmBitsPerPel);
1690 else
1692 FIXME_(d3d_caps)("Adapter not primary display\n");
1695 return WINED3D_OK;
1698 static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, WINED3DDISPLAYMODE* pMode) {
1699 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1700 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
1702 if (NULL == pMode ||
1703 Adapter >= IWineD3D_GetAdapterCount(iface)) {
1704 return WINED3DERR_INVALIDCALL;
1707 if (Adapter == 0) { /* Display */
1708 int bpp = 0;
1709 DEVMODEW DevModeW;
1711 ZeroMemory(&DevModeW, sizeof(DevModeW));
1712 DevModeW.dmSize = sizeof(DevModeW);
1714 EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &DevModeW, 0);
1715 pMode->Width = DevModeW.dmPelsWidth;
1716 pMode->Height = DevModeW.dmPelsHeight;
1717 bpp = DevModeW.dmBitsPerPel;
1718 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1719 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
1721 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1724 pMode->Format = pixelformat_for_depth(bpp);
1725 } else {
1726 FIXME_(d3d_caps)("Adapter not primary display\n");
1729 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
1730 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
1731 return WINED3D_OK;
1734 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
1735 and fields being inserted in the middle, a new structure is used in place */
1736 static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
1737 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
1738 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1740 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %x, pId=%p)\n", This, Adapter, Flags, pIdentifier);
1742 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1743 return WINED3DERR_INVALIDCALL;
1746 /* Return the information requested */
1747 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
1748 strcpy(pIdentifier->Driver, This->adapters[Adapter].driver);
1749 if(This->adapters[Adapter].gl_info.driver_description)
1750 strcpy(pIdentifier->Description, This->adapters[Adapter].gl_info.driver_description);
1751 else /* Copy default description "Direct3D HAL" */
1752 strcpy(pIdentifier->Description, This->adapters[Adapter].description);
1754 /* Note dx8 doesn't supply a DeviceName */
1755 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY1"); /* FIXME: May depend on desktop? */
1756 pIdentifier->DriverVersion->u.HighPart = This->adapters[Adapter].gl_info.driver_version_hipart;
1757 pIdentifier->DriverVersion->u.LowPart = This->adapters[Adapter].gl_info.driver_version;
1758 *(pIdentifier->VendorId) = This->adapters[Adapter].gl_info.gl_vendor;
1759 *(pIdentifier->DeviceId) = This->adapters[Adapter].gl_info.gl_card;
1760 *(pIdentifier->SubSysId) = 0;
1761 *(pIdentifier->Revision) = 0;
1762 *pIdentifier->DeviceIdentifier = IID_D3DDEVICE_D3DUID;
1764 if(wined3d_settings.pci_device_id != PCI_DEVICE_NONE)
1766 TRACE_(d3d_caps)("Overriding pci device id with: %x\n", wined3d_settings.pci_device_id);
1767 *(pIdentifier->DeviceId) = wined3d_settings.pci_device_id;
1770 if(wined3d_settings.pci_vendor_id != PCI_VENDOR_NONE)
1772 TRACE_(d3d_caps)("Overriding pci vendor id with: %x\n", wined3d_settings.pci_vendor_id);
1773 *(pIdentifier->VendorId) = wined3d_settings.pci_vendor_id;
1776 if (Flags & WINED3DENUM_NO_WHQL_LEVEL) {
1777 *(pIdentifier->WHQLLevel) = 0;
1778 } else {
1779 *(pIdentifier->WHQLLevel) = 1;
1782 return WINED3D_OK;
1785 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const WineD3D_GL_Info *gl_info,
1786 const WineD3D_PixelFormat *cfg, const struct GlPixelFormatDesc *format_desc)
1788 short redSize, greenSize, blueSize, alphaSize, colorBits;
1790 if(!cfg)
1791 return FALSE;
1793 if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */
1794 if (!getColorBits(format_desc, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
1796 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(format_desc->format));
1797 return FALSE;
1800 if(cfg->redSize < redSize)
1801 return FALSE;
1803 if(cfg->greenSize < greenSize)
1804 return FALSE;
1806 if(cfg->blueSize < blueSize)
1807 return FALSE;
1809 if(cfg->alphaSize < alphaSize)
1810 return FALSE;
1812 return TRUE;
1813 } else if(cfg->iPixelType == WGL_TYPE_RGBA_FLOAT_ARB) { /* Float RGBA formats; TODO: WGL_NV_float_buffer */
1814 if (format_desc->format == WINED3DFMT_R16_FLOAT)
1815 return (cfg->redSize == 16 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1816 if (format_desc->format == WINED3DFMT_R16G16_FLOAT)
1817 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1818 if (format_desc->format == WINED3DFMT_R16G16B16A16_FLOAT)
1819 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 16 && cfg->alphaSize == 16);
1820 if (format_desc->format == WINED3DFMT_R32_FLOAT)
1821 return (cfg->redSize == 32 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1822 if (format_desc->format == WINED3DFMT_R32G32_FLOAT)
1823 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1824 if (format_desc->format == WINED3DFMT_R32G32B32A32_FLOAT)
1825 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 32 && cfg->alphaSize == 32);
1826 } else {
1827 /* Probably a color index mode */
1828 return FALSE;
1831 return FALSE;
1834 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const WineD3D_GL_Info *gl_info,
1835 const WineD3D_PixelFormat *cfg, const struct GlPixelFormatDesc *format_desc)
1837 short depthSize, stencilSize;
1838 BOOL lockable = FALSE;
1840 if(!cfg)
1841 return FALSE;
1843 if (!getDepthStencilBits(format_desc, &depthSize, &stencilSize))
1845 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(format_desc->format));
1846 return FALSE;
1849 if ((format_desc->format == WINED3DFMT_D16_LOCKABLE) || (format_desc->format == WINED3DFMT_D32F_LOCKABLE))
1850 lockable = TRUE;
1852 /* On some modern cards like the Geforce8/9 GLX doesn't offer some dephthstencil formats which D3D9 reports.
1853 * We can safely report 'compatible' formats (e.g. D24 can be used for D16) as long as we aren't dealing with
1854 * a lockable format. This also helps D3D <= 7 as they expect D16 which isn't offered without this on Geforce8 cards. */
1855 if(!(cfg->depthSize == depthSize || (!lockable && cfg->depthSize > depthSize)))
1856 return FALSE;
1858 /* Some cards like Intel i915 ones only offer D24S8 but lots of games also need a format without stencil, so
1859 * allow more stencil bits than requested. */
1860 if(cfg->stencilSize < stencilSize)
1861 return FALSE;
1863 return TRUE;
1866 static HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1867 WINED3DFORMAT AdapterFormat,
1868 WINED3DFORMAT RenderTargetFormat,
1869 WINED3DFORMAT DepthStencilFormat) {
1870 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1871 int nCfgs;
1872 const WineD3D_PixelFormat *cfgs;
1873 const struct WineD3DAdapter *adapter;
1874 const struct GlPixelFormatDesc *rt_format_desc;
1875 const struct GlPixelFormatDesc *ds_format_desc;
1876 int it;
1878 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
1879 This, Adapter,
1880 DeviceType, debug_d3ddevicetype(DeviceType),
1881 AdapterFormat, debug_d3dformat(AdapterFormat),
1882 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
1883 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
1885 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1886 TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning WINED3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
1887 return WINED3DERR_INVALIDCALL;
1890 adapter = &This->adapters[Adapter];
1891 rt_format_desc = getFormatDescEntry(RenderTargetFormat, &adapter->gl_info);
1892 ds_format_desc = getFormatDescEntry(DepthStencilFormat, &adapter->gl_info);
1893 cfgs = adapter->cfgs;
1894 nCfgs = adapter->nCfgs;
1895 for (it = 0; it < nCfgs; ++it) {
1896 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, &cfgs[it], rt_format_desc))
1898 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[it], ds_format_desc))
1900 TRACE_(d3d_caps)("(%p) : Formats matched\n", This);
1901 return WINED3D_OK;
1905 WARN_(d3d_caps)("unsupported format pair: %s and %s\n", debug_d3dformat(RenderTargetFormat), debug_d3dformat(DepthStencilFormat));
1907 return WINED3DERR_NOTAVAILABLE;
1910 static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1911 WINED3DFORMAT SurfaceFormat,
1912 BOOL Windowed, WINED3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
1914 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1915 const struct GlPixelFormatDesc *glDesc;
1916 const struct WineD3DAdapter *adapter;
1918 TRACE_(d3d_caps)("(%p)-> (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
1919 This,
1920 Adapter,
1921 DeviceType, debug_d3ddevicetype(DeviceType),
1922 SurfaceFormat, debug_d3dformat(SurfaceFormat),
1923 Windowed,
1924 MultiSampleType,
1925 pQualityLevels);
1927 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1928 return WINED3DERR_INVALIDCALL;
1931 /* TODO: handle Windowed, add more quality levels */
1933 if (WINED3DMULTISAMPLE_NONE == MultiSampleType) {
1934 if(pQualityLevels) *pQualityLevels = 1;
1935 return WINED3D_OK;
1938 /* By default multisampling is disabled right now as it causes issues
1939 * on some Nvidia driver versions and it doesn't work well in combination
1940 * with FBOs yet. */
1941 if(!wined3d_settings.allow_multisampling)
1942 return WINED3DERR_NOTAVAILABLE;
1944 adapter = &This->adapters[Adapter];
1945 glDesc = getFormatDescEntry(SurfaceFormat, &adapter->gl_info);
1946 if (!glDesc) return WINED3DERR_INVALIDCALL;
1948 if(glDesc->Flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)) {
1949 int i, nCfgs;
1950 const WineD3D_PixelFormat *cfgs;
1952 cfgs = adapter->cfgs;
1953 nCfgs = adapter->nCfgs;
1954 for(i=0; i<nCfgs; i++) {
1955 if(cfgs[i].numSamples != MultiSampleType)
1956 continue;
1958 if (!IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[i], glDesc))
1959 continue;
1961 TRACE("Found iPixelFormat=%d to support MultiSampleType=%d for format %s\n", cfgs[i].iPixelFormat, MultiSampleType, debug_d3dformat(SurfaceFormat));
1963 if(pQualityLevels)
1964 *pQualityLevels = 1; /* Guess at a value! */
1965 return WINED3D_OK;
1968 else if(glDesc->Flags & WINED3DFMT_FLAG_RENDERTARGET) {
1969 short redSize, greenSize, blueSize, alphaSize, colorBits;
1970 int i, nCfgs;
1971 const WineD3D_PixelFormat *cfgs;
1973 if (!getColorBits(glDesc, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
1975 ERR("Unable to color bits for format %#x, can't check multisampling capability!\n", SurfaceFormat);
1976 return WINED3DERR_NOTAVAILABLE;
1979 cfgs = adapter->cfgs;
1980 nCfgs = adapter->nCfgs;
1981 for(i=0; i<nCfgs; i++) {
1982 if(cfgs[i].numSamples != MultiSampleType)
1983 continue;
1984 if(cfgs[i].redSize != redSize)
1985 continue;
1986 if(cfgs[i].greenSize != greenSize)
1987 continue;
1988 if(cfgs[i].blueSize != blueSize)
1989 continue;
1990 if(cfgs[i].alphaSize != alphaSize)
1991 continue;
1993 TRACE("Found iPixelFormat=%d to support MultiSampleType=%d for format %s\n", cfgs[i].iPixelFormat, MultiSampleType, debug_d3dformat(SurfaceFormat));
1995 if(pQualityLevels)
1996 *pQualityLevels = 1; /* Guess at a value! */
1997 return WINED3D_OK;
2000 return WINED3DERR_NOTAVAILABLE;
2003 static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2004 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
2006 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2007 HRESULT hr = WINED3DERR_NOTAVAILABLE;
2008 UINT nmodes;
2010 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
2011 This,
2012 Adapter,
2013 DeviceType, debug_d3ddevicetype(DeviceType),
2014 DisplayFormat, debug_d3dformat(DisplayFormat),
2015 BackBufferFormat, debug_d3dformat(BackBufferFormat),
2016 Windowed);
2018 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2019 WARN_(d3d_caps)("Adapter >= IWineD3D_GetAdapterCount(iface), returning WINED3DERR_INVALIDCALL\n");
2020 return WINED3DERR_INVALIDCALL;
2023 /* The task of this function is to check whether a certain display / backbuffer format
2024 * combination is available on the given adapter. In fullscreen mode microsoft specified
2025 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
2026 * and display format should match exactly.
2027 * In windowed mode format conversion can occur and this depends on the driver. When format
2028 * conversion is done, this function should nevertheless fail and applications need to use
2029 * CheckDeviceFormatConversion.
2030 * At the moment we assume that fullscreen and windowed have the same capabilities */
2032 /* There are only 4 display formats */
2033 if(!((DisplayFormat == WINED3DFMT_R5G6B5) ||
2034 (DisplayFormat == WINED3DFMT_X1R5G5B5) ||
2035 (DisplayFormat == WINED3DFMT_X8R8G8B8) ||
2036 (DisplayFormat == WINED3DFMT_A2R10G10B10)))
2038 TRACE_(d3d_caps)("Format %s unsupported as display format\n", debug_d3dformat(DisplayFormat));
2039 return WINED3DERR_NOTAVAILABLE;
2042 /* If the requested DisplayFormat is not available, don't continue */
2043 nmodes = IWineD3DImpl_GetAdapterModeCount(iface, Adapter, DisplayFormat);
2044 if(!nmodes) {
2045 TRACE_(d3d_caps)("No available modes for display format %s\n", debug_d3dformat(DisplayFormat));
2046 return WINED3DERR_NOTAVAILABLE;
2049 /* Windowed mode allows you to specify WINED3DFMT_UNKNOWN for the backbufferformat, it means 'reuse' the display format for the backbuffer */
2050 if(!Windowed && BackBufferFormat == WINED3DFMT_UNKNOWN) {
2051 TRACE_(d3d_caps)("BackBufferFormat WINED3FMT_UNKNOWN not available in Windowed mode\n");
2052 return WINED3DERR_NOTAVAILABLE;
2055 /* In FULLSCREEN mode R5G6B5 can only be mixed with backbuffer format R5G6B5 */
2056 if( (DisplayFormat == WINED3DFMT_R5G6B5) && (BackBufferFormat != WINED3DFMT_R5G6B5) ) {
2057 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2058 return WINED3DERR_NOTAVAILABLE;
2061 /* In FULLSCREEN mode X1R5G5B5 can only be mixed with backbuffer format *1R5G5B5 */
2062 if( (DisplayFormat == WINED3DFMT_X1R5G5B5) && !((BackBufferFormat == WINED3DFMT_X1R5G5B5) || (BackBufferFormat == WINED3DFMT_A1R5G5B5)) ) {
2063 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2064 return WINED3DERR_NOTAVAILABLE;
2067 /* In FULLSCREEN mode X8R8G8B8 can only be mixed with backbuffer format *8R8G8B8 */
2068 if( (DisplayFormat == WINED3DFMT_X8R8G8B8) && !((BackBufferFormat == WINED3DFMT_X8R8G8B8) || (BackBufferFormat == WINED3DFMT_A8R8G8B8)) ) {
2069 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2070 return WINED3DERR_NOTAVAILABLE;
2073 /* A2R10G10B10 is only allowed in fullscreen mode and it can only be mixed with backbuffer format A2R10G10B10 */
2074 if( (DisplayFormat == WINED3DFMT_A2R10G10B10) && ((BackBufferFormat != WINED3DFMT_A2R10G10B10) || Windowed)) {
2075 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2076 return WINED3DERR_NOTAVAILABLE;
2079 /* Use CheckDeviceFormat to see if the BackBufferFormat is usable with the given DisplayFormat */
2080 hr = IWineD3DImpl_CheckDeviceFormat(iface, Adapter, DeviceType, DisplayFormat, WINED3DUSAGE_RENDERTARGET, WINED3DRTYPE_SURFACE, BackBufferFormat, SURFACE_OPENGL);
2081 if(FAILED(hr))
2082 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2084 return hr;
2088 /* Check if we support bumpmapping for a format */
2089 static BOOL CheckBumpMapCapability(struct WineD3DAdapter *adapter,
2090 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
2092 const struct fragment_pipeline *fp;
2094 switch(format_desc->format)
2096 case WINED3DFMT_R8G8_SNORM:
2097 case WINED3DFMT_R16G16_SNORM:
2098 case WINED3DFMT_L6V5U5:
2099 case WINED3DFMT_X8L8V8U8:
2100 case WINED3DFMT_R8G8B8A8_SNORM:
2101 /* Ask the fixed function pipeline implementation if it can deal
2102 * with the conversion. If we've got a GL extension giving native
2103 * support this will be an identity conversion. */
2104 fp = select_fragment_implementation(adapter, DeviceType);
2105 if (fp->color_fixup_supported(format_desc->color_fixup))
2107 TRACE_(d3d_caps)("[OK]\n");
2108 return TRUE;
2110 TRACE_(d3d_caps)("[FAILED]\n");
2111 return FALSE;
2113 default:
2114 TRACE_(d3d_caps)("[FAILED]\n");
2115 return FALSE;
2119 /* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
2120 static BOOL CheckDepthStencilCapability(struct WineD3DAdapter *adapter,
2121 const struct GlPixelFormatDesc *display_format_desc, const struct GlPixelFormatDesc *ds_format_desc)
2123 int it=0;
2125 /* Only allow depth/stencil formats */
2126 if (!(ds_format_desc->Flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))) return FALSE;
2128 /* Walk through all WGL pixel formats to find a match */
2129 for (it = 0; it < adapter->nCfgs; ++it)
2131 WineD3D_PixelFormat *cfg = &adapter->cfgs[it];
2132 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, cfg, display_format_desc))
2134 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, cfg, ds_format_desc))
2136 return TRUE;
2141 return FALSE;
2144 static BOOL CheckFilterCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2146 /* The flags entry of a format contains the filtering capability */
2147 if (format_desc->Flags & WINED3DFMT_FLAG_FILTERING) return TRUE;
2149 return FALSE;
2152 /* Check the render target capabilities of a format */
2153 static BOOL CheckRenderTargetCapability(struct WineD3DAdapter *adapter,
2154 const struct GlPixelFormatDesc *adapter_format_desc, const struct GlPixelFormatDesc *check_format_desc)
2156 /* Filter out non-RT formats */
2157 if (!(check_format_desc->Flags & WINED3DFMT_FLAG_RENDERTARGET)) return FALSE;
2159 if(wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) {
2160 WineD3D_PixelFormat *cfgs = adapter->cfgs;
2161 int it;
2162 short AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
2163 short CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
2165 getColorBits(adapter_format_desc, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
2166 getColorBits(check_format_desc, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
2168 /* In backbuffer mode the front and backbuffer share the same WGL pixelformat.
2169 * The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */
2170 if(!((AdapterRed == CheckRed) && (AdapterGreen == CheckGreen) && (AdapterBlue == CheckBlue))) {
2171 TRACE_(d3d_caps)("[FAILED]\n");
2172 return FALSE;
2175 /* Check if there is a WGL pixel format matching the requirements, the format should also be window
2176 * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
2177 for (it = 0; it < adapter->nCfgs; ++it)
2179 if (cfgs[it].windowDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info,
2180 &cfgs[it], check_format_desc))
2182 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n",
2183 cfgs[it].iPixelFormat, debug_d3dformat(check_format_desc->format));
2184 return TRUE;
2187 } else if(wined3d_settings.offscreen_rendering_mode == ORM_PBUFFER) {
2188 /* We can probably use this function in FBO mode too on some drivers to get some basic indication of the capabilities. */
2189 WineD3D_PixelFormat *cfgs = adapter->cfgs;
2190 int it;
2192 /* Check if there is a WGL pixel format matching the requirements, the pixel format should also be usable with pbuffers */
2193 for (it = 0; it < adapter->nCfgs; ++it)
2195 if (cfgs[it].pbufferDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info,
2196 &cfgs[it], check_format_desc))
2198 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n",
2199 cfgs[it].iPixelFormat, debug_d3dformat(check_format_desc->format));
2200 return TRUE;
2203 } else if(wined3d_settings.offscreen_rendering_mode == ORM_FBO){
2204 /* For now return TRUE for FBOs until we have some proper checks.
2205 * Note that this function will only be called when the format is around for texturing. */
2206 return TRUE;
2208 return FALSE;
2211 static BOOL CheckSrgbReadCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2213 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
2215 /* Check for supported sRGB formats (Texture loading and framebuffer) */
2216 if(!GL_SUPPORT(EXT_TEXTURE_SRGB)) {
2217 TRACE_(d3d_caps)("[FAILED] GL_EXT_texture_sRGB not supported\n");
2218 return FALSE;
2221 switch (format_desc->format)
2223 case WINED3DFMT_A8R8G8B8:
2224 case WINED3DFMT_X8R8G8B8:
2225 case WINED3DFMT_A4R4G4B4:
2226 case WINED3DFMT_L8:
2227 case WINED3DFMT_A8L8:
2228 case WINED3DFMT_DXT1:
2229 case WINED3DFMT_DXT2:
2230 case WINED3DFMT_DXT3:
2231 case WINED3DFMT_DXT4:
2232 case WINED3DFMT_DXT5:
2233 TRACE_(d3d_caps)("[OK]\n");
2234 return TRUE;
2236 default:
2237 TRACE_(d3d_caps)("[FAILED] Gamma texture format %s not supported.\n", debug_d3dformat(format_desc->format));
2238 return FALSE;
2240 return FALSE;
2243 static BOOL CheckSrgbWriteCapability(struct WineD3DAdapter *adapter,
2244 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
2246 /* Only offer SRGB writing on X8R8G8B8/A8R8G8B8 when we use ARB or GLSL shaders as we are
2247 * doing the color fixup in shaders.
2248 * Note Windows drivers (at least on the Geforce 8800) also offer this on R5G6B5. */
2249 if ((format_desc->format == WINED3DFMT_X8R8G8B8) || (format_desc->format == WINED3DFMT_A8R8G8B8))
2251 int vs_selected_mode;
2252 int ps_selected_mode;
2253 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
2255 if((ps_selected_mode == SHADER_ARB) || (ps_selected_mode == SHADER_GLSL)) {
2256 TRACE_(d3d_caps)("[OK]\n");
2257 return TRUE;
2261 TRACE_(d3d_caps)("[FAILED] - no SRGB writing support on format=%s\n", debug_d3dformat(format_desc->format));
2262 return FALSE;
2265 /* Check if a format support blending in combination with pixel shaders */
2266 static BOOL CheckPostPixelShaderBlendingCapability(struct WineD3DAdapter *adapter,
2267 const struct GlPixelFormatDesc *format_desc)
2269 /* The flags entry of a format contains the post pixel shader blending capability */
2270 if (format_desc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING) return TRUE;
2272 return FALSE;
2275 static BOOL CheckWrapAndMipCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2277 /* OpenGL supports mipmapping on all formats basically. Wrapping is unsupported,
2278 * but we have to report mipmapping so we cannot reject this flag. Tests show that
2279 * windows reports WRAPANDMIP on unfilterable surfaces as well, apparently to show
2280 * that wrapping is supported. The lack of filtering will sort out the mipmapping
2281 * capability anyway.
2283 * For now lets report this on all formats, but in the future we may want to
2284 * restrict it to some should games need that
2286 return TRUE;
2289 /* Check if a texture format is supported on the given adapter */
2290 static BOOL CheckTextureCapability(struct WineD3DAdapter *adapter,
2291 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
2293 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
2294 const shader_backend_t *shader_backend;
2295 const struct fragment_pipeline *fp;
2297 switch (format_desc->format)
2299 /*****
2300 * supported: RGB(A) formats
2302 case WINED3DFMT_R8G8B8: /* Enable for dx7, blacklisted for 8 and 9 above */
2303 case WINED3DFMT_A8R8G8B8:
2304 case WINED3DFMT_X8R8G8B8:
2305 case WINED3DFMT_R5G6B5:
2306 case WINED3DFMT_X1R5G5B5:
2307 case WINED3DFMT_A1R5G5B5:
2308 case WINED3DFMT_A4R4G4B4:
2309 case WINED3DFMT_A8_UNORM:
2310 case WINED3DFMT_X4R4G4B4:
2311 case WINED3DFMT_R8G8B8A8_UNORM:
2312 case WINED3DFMT_X8B8G8R8:
2313 case WINED3DFMT_A2R10G10B10:
2314 case WINED3DFMT_R10G10B10A2_UNORM:
2315 case WINED3DFMT_R16G16_UNORM:
2316 TRACE_(d3d_caps)("[OK]\n");
2317 return TRUE;
2319 case WINED3DFMT_R3G3B2:
2320 TRACE_(d3d_caps)("[FAILED] - Not supported on Windows\n");
2321 return FALSE;
2323 /*****
2324 * supported: Palettized
2326 case WINED3DFMT_P8:
2327 TRACE_(d3d_caps)("[OK]\n");
2328 return TRUE;
2329 /* No Windows driver offers A8P8, so don't offer it either */
2330 case WINED3DFMT_A8P8:
2331 return FALSE;
2333 /*****
2334 * Supported: (Alpha)-Luminance
2336 case WINED3DFMT_L8:
2337 case WINED3DFMT_A8L8:
2338 case WINED3DFMT_L16:
2339 TRACE_(d3d_caps)("[OK]\n");
2340 return TRUE;
2342 /* Not supported on Windows, thus disabled */
2343 case WINED3DFMT_A4L4:
2344 TRACE_(d3d_caps)("[FAILED] - not supported on windows\n");
2345 return FALSE;
2347 /*****
2348 * Supported: Depth/Stencil formats
2350 case WINED3DFMT_D16_LOCKABLE:
2351 case WINED3DFMT_D16_UNORM:
2352 case WINED3DFMT_D15S1:
2353 case WINED3DFMT_D24X8:
2354 case WINED3DFMT_D24X4S4:
2355 case WINED3DFMT_D24S8:
2356 case WINED3DFMT_D24FS8:
2357 case WINED3DFMT_D32:
2358 case WINED3DFMT_D32F_LOCKABLE:
2359 return TRUE;
2361 /*****
2362 * Not supported everywhere(depends on GL_ATI_envmap_bumpmap or
2363 * GL_NV_texture_shader). Emulated by shaders
2365 case WINED3DFMT_R8G8_SNORM:
2366 case WINED3DFMT_X8L8V8U8:
2367 case WINED3DFMT_L6V5U5:
2368 case WINED3DFMT_R8G8B8A8_SNORM:
2369 case WINED3DFMT_R16G16_SNORM:
2370 /* Ask the shader backend if it can deal with the conversion. If
2371 * we've got a GL extension giving native support this will be an
2372 * identity conversion. */
2373 shader_backend = select_shader_backend(adapter, DeviceType);
2374 if (shader_backend->shader_color_fixup_supported(format_desc->color_fixup))
2376 TRACE_(d3d_caps)("[OK]\n");
2377 return TRUE;
2379 TRACE_(d3d_caps)("[FAILED]\n");
2380 return FALSE;
2382 case WINED3DFMT_DXT1:
2383 case WINED3DFMT_DXT2:
2384 case WINED3DFMT_DXT3:
2385 case WINED3DFMT_DXT4:
2386 case WINED3DFMT_DXT5:
2387 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
2388 TRACE_(d3d_caps)("[OK]\n");
2389 return TRUE;
2391 TRACE_(d3d_caps)("[FAILED]\n");
2392 return FALSE;
2395 /*****
2396 * Odd formats - not supported
2398 case WINED3DFMT_VERTEXDATA:
2399 case WINED3DFMT_R16_UINT:
2400 case WINED3DFMT_R32_UINT:
2401 case WINED3DFMT_R16G16B16A16_SNORM:
2402 case WINED3DFMT_A2W10V10U10:
2403 case WINED3DFMT_W11V11U10:
2404 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2405 return FALSE;
2407 /*****
2408 * WINED3DFMT_CxV8U8: Not supported right now
2410 case WINED3DFMT_CxV8U8:
2411 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2412 return FALSE;
2414 /* YUV formats */
2415 case WINED3DFMT_UYVY:
2416 case WINED3DFMT_YUY2:
2417 if(GL_SUPPORT(APPLE_YCBCR_422)) {
2418 TRACE_(d3d_caps)("[OK]\n");
2419 return TRUE;
2421 TRACE_(d3d_caps)("[FAILED]\n");
2422 return FALSE;
2423 case WINED3DFMT_YV12:
2424 TRACE_(d3d_caps)("[FAILED]\n");
2425 return FALSE;
2427 /* Not supported */
2428 case WINED3DFMT_R16G16B16A16_UNORM:
2429 case WINED3DFMT_A8R3G3B2:
2430 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2431 return FALSE;
2433 /* Floating point formats */
2434 case WINED3DFMT_R16_FLOAT:
2435 case WINED3DFMT_R16G16_FLOAT:
2436 case WINED3DFMT_R16G16B16A16_FLOAT:
2437 if(GL_SUPPORT(ARB_TEXTURE_FLOAT) && GL_SUPPORT(ARB_HALF_FLOAT_PIXEL)) {
2438 TRACE_(d3d_caps)("[OK]\n");
2439 return TRUE;
2441 TRACE_(d3d_caps)("[FAILED]\n");
2442 return FALSE;
2444 case WINED3DFMT_R32_FLOAT:
2445 case WINED3DFMT_R32G32_FLOAT:
2446 case WINED3DFMT_R32G32B32A32_FLOAT:
2447 if (GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2448 TRACE_(d3d_caps)("[OK]\n");
2449 return TRUE;
2451 TRACE_(d3d_caps)("[FAILED]\n");
2452 return FALSE;
2454 /* ATI instancing hack: Although ATI cards do not support Shader Model 3.0, they support
2455 * instancing. To query if the card supports instancing CheckDeviceFormat with the special format
2456 * MAKEFOURCC('I','N','S','T') is used. Should a (broken) app check for this provide a proper return value.
2457 * We can do instancing with all shader versions, but we need vertex shaders.
2459 * Additionally applications have to set the D3DRS_POINTSIZE render state to MAKEFOURCC('I','N','S','T') once
2460 * to enable instancing. WineD3D doesn't need that and just ignores it.
2462 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows.
2464 case WINEMAKEFOURCC('I','N','S','T'):
2465 TRACE("ATI Instancing check hack\n");
2466 if(GL_SUPPORT(ARB_VERTEX_PROGRAM) || GL_SUPPORT(ARB_VERTEX_SHADER)) {
2467 TRACE_(d3d_caps)("[OK]\n");
2468 return TRUE;
2470 TRACE_(d3d_caps)("[FAILED]\n");
2471 return FALSE;
2473 /* Some weird FOURCC formats */
2474 case WINED3DFMT_R8G8_B8G8:
2475 case WINED3DFMT_G8R8_G8B8:
2476 case WINED3DFMT_MULTI2_ARGB8:
2477 TRACE_(d3d_caps)("[FAILED]\n");
2478 return FALSE;
2480 /* Vendor specific formats */
2481 case WINED3DFMT_ATI2N:
2482 if(GL_SUPPORT(ATI_TEXTURE_COMPRESSION_3DC) || GL_SUPPORT(EXT_TEXTURE_COMPRESSION_RGTC)) {
2483 shader_backend = select_shader_backend(adapter, DeviceType);
2484 fp = select_fragment_implementation(adapter, DeviceType);
2485 if (shader_backend->shader_color_fixup_supported(format_desc->color_fixup)
2486 && fp->color_fixup_supported(format_desc->color_fixup))
2488 TRACE_(d3d_caps)("[OK]\n");
2489 return TRUE;
2492 TRACE_(d3d_caps)("[OK]\n");
2493 return TRUE;
2495 TRACE_(d3d_caps)("[FAILED]\n");
2496 return FALSE;
2498 case WINED3DFMT_NVHU:
2499 case WINED3DFMT_NVHS:
2500 /* These formats seem to be similar to the HILO formats in GL_NV_texture_shader. NVHU
2501 * is said to be GL_UNSIGNED_HILO16, NVHS GL_SIGNED_HILO16. Rumours say that d3d computes
2502 * a 3rd channel similarly to D3DFMT_CxV8U8(So NVHS could be called D3DFMT_CxV16U16).
2503 * ATI refused to support formats which can easilly be emulated with pixel shaders, so
2504 * Applications have to deal with not having NVHS and NVHU.
2506 TRACE_(d3d_caps)("[FAILED]\n");
2507 return FALSE;
2509 case WINED3DFMT_UNKNOWN:
2510 return FALSE;
2512 default:
2513 ERR("Unhandled format=%s\n", debug_d3dformat(format_desc->format));
2514 break;
2516 return FALSE;
2519 static BOOL CheckSurfaceCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *adapter_format_desc,
2520 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *check_format_desc, WINED3DSURFTYPE SurfaceType)
2522 const struct blit_shader *blitter;
2524 if(SurfaceType == SURFACE_GDI) {
2525 switch(check_format_desc->format)
2527 case WINED3DFMT_R8G8B8:
2528 case WINED3DFMT_A8R8G8B8:
2529 case WINED3DFMT_X8R8G8B8:
2530 case WINED3DFMT_R5G6B5:
2531 case WINED3DFMT_X1R5G5B5:
2532 case WINED3DFMT_A1R5G5B5:
2533 case WINED3DFMT_A4R4G4B4:
2534 case WINED3DFMT_R3G3B2:
2535 case WINED3DFMT_A8_UNORM:
2536 case WINED3DFMT_A8R3G3B2:
2537 case WINED3DFMT_X4R4G4B4:
2538 case WINED3DFMT_R10G10B10A2_UNORM:
2539 case WINED3DFMT_R8G8B8A8_UNORM:
2540 case WINED3DFMT_X8B8G8R8:
2541 case WINED3DFMT_R16G16_UNORM:
2542 case WINED3DFMT_A2R10G10B10:
2543 case WINED3DFMT_R16G16B16A16_UNORM:
2544 case WINED3DFMT_P8:
2545 TRACE_(d3d_caps)("[OK]\n");
2546 return TRUE;
2547 default:
2548 TRACE_(d3d_caps)("[FAILED] - not available on GDI surfaces\n");
2549 return FALSE;
2553 /* All format that are supported for textures are supported for surfaces as well */
2554 if (CheckTextureCapability(adapter, DeviceType, check_format_desc)) return TRUE;
2555 /* All depth stencil formats are supported on surfaces */
2556 if (CheckDepthStencilCapability(adapter, adapter_format_desc, check_format_desc)) return TRUE;
2558 /* If opengl can't process the format natively, the blitter may be able to convert it */
2559 blitter = select_blit_implementation(adapter, DeviceType);
2560 if (blitter->color_fixup_supported(check_format_desc->color_fixup))
2562 TRACE_(d3d_caps)("[OK]\n");
2563 return TRUE;
2566 /* Reject other formats */
2567 TRACE_(d3d_caps)("[FAILED]\n");
2568 return FALSE;
2571 static BOOL CheckVertexTextureCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2573 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
2575 if (!GL_LIMITS(vertex_samplers)) {
2576 TRACE_(d3d_caps)("[FAILED]\n");
2577 return FALSE;
2580 switch (format_desc->format)
2582 case WINED3DFMT_R32G32B32A32_FLOAT:
2583 if (!GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2584 TRACE_(d3d_caps)("[FAILED]\n");
2585 return FALSE;
2587 TRACE_(d3d_caps)("[OK]\n");
2588 return TRUE;
2590 default:
2591 TRACE_(d3d_caps)("[FAILED]\n");
2592 return FALSE;
2594 return FALSE;
2597 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2598 WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat,
2599 WINED3DSURFTYPE SurfaceType) {
2600 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2601 struct WineD3DAdapter *adapter = &This->adapters[Adapter];
2602 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
2603 const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(CheckFormat, gl_info);
2604 const struct GlPixelFormatDesc *adapter_format_desc = getFormatDescEntry(AdapterFormat, gl_info);
2605 DWORD UsageCaps = 0;
2607 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%u,%s,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s))\n",
2608 This,
2609 Adapter,
2610 DeviceType, debug_d3ddevicetype(DeviceType),
2611 AdapterFormat, debug_d3dformat(AdapterFormat),
2612 Usage, debug_d3dusage(Usage), debug_d3dusagequery(Usage),
2613 RType, debug_d3dresourcetype(RType),
2614 CheckFormat, debug_d3dformat(CheckFormat));
2616 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2617 return WINED3DERR_INVALIDCALL;
2620 if(RType == WINED3DRTYPE_CUBETEXTURE) {
2622 if(SurfaceType != SURFACE_OPENGL) {
2623 TRACE("[FAILED]\n");
2624 return WINED3DERR_NOTAVAILABLE;
2627 /* Cubetexture allows:
2628 * - D3DUSAGE_AUTOGENMIPMAP
2629 * - D3DUSAGE_DEPTHSTENCIL
2630 * - D3DUSAGE_DYNAMIC
2631 * - D3DUSAGE_NONSECURE (d3d9ex)
2632 * - D3DUSAGE_RENDERTARGET
2633 * - D3DUSAGE_SOFTWAREPROCESSING
2634 * - D3DUSAGE_QUERY_WRAPANDMIP
2636 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2637 /* Check if the texture format is around */
2638 if (CheckTextureCapability(adapter, DeviceType, format_desc))
2640 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
2641 /* Check for automatic mipmap generation support */
2642 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2643 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
2644 } else {
2645 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUTOGEN instead of D3D_OK */
2646 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
2650 /* Always report dynamic locking */
2651 if(Usage & WINED3DUSAGE_DYNAMIC)
2652 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2654 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2655 if(CheckRenderTargetCapability(adapter, adapter_format_desc, format_desc))
2657 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2658 } else {
2659 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2660 return WINED3DERR_NOTAVAILABLE;
2664 /* Always report software processing */
2665 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2666 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2668 /* Check QUERY_FILTER support */
2669 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2670 if (CheckFilterCapability(adapter, format_desc))
2672 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2673 } else {
2674 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2675 return WINED3DERR_NOTAVAILABLE;
2679 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2680 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2681 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
2683 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2684 } else {
2685 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2686 return WINED3DERR_NOTAVAILABLE;
2690 /* Check QUERY_SRGBREAD support */
2691 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2692 if (CheckSrgbReadCapability(adapter, format_desc))
2694 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2695 } else {
2696 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2697 return WINED3DERR_NOTAVAILABLE;
2701 /* Check QUERY_SRGBWRITE support */
2702 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2703 if (CheckSrgbWriteCapability(adapter, DeviceType, format_desc))
2705 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2706 } else {
2707 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2708 return WINED3DERR_NOTAVAILABLE;
2712 /* Check QUERY_VERTEXTEXTURE support */
2713 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2714 if (CheckVertexTextureCapability(adapter, format_desc))
2716 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2717 } else {
2718 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2719 return WINED3DERR_NOTAVAILABLE;
2723 /* Check QUERY_WRAPANDMIP support */
2724 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
2725 if (CheckWrapAndMipCapability(adapter, format_desc))
2727 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
2728 } else {
2729 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
2730 return WINED3DERR_NOTAVAILABLE;
2733 } else {
2734 TRACE_(d3d_caps)("[FAILED] - Cube texture format not supported\n");
2735 return WINED3DERR_NOTAVAILABLE;
2737 } else {
2738 TRACE_(d3d_caps)("[FAILED] - No cube texture support\n");
2739 return WINED3DERR_NOTAVAILABLE;
2741 } else if(RType == WINED3DRTYPE_SURFACE) {
2742 /* Surface allows:
2743 * - D3DUSAGE_DEPTHSTENCIL
2744 * - D3DUSAGE_NONSECURE (d3d9ex)
2745 * - D3DUSAGE_RENDERTARGET
2748 if (CheckSurfaceCapability(adapter, adapter_format_desc, DeviceType, format_desc, SurfaceType))
2750 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
2751 if (CheckDepthStencilCapability(adapter, adapter_format_desc, format_desc))
2753 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
2754 } else {
2755 TRACE_(d3d_caps)("[FAILED] - No depthstencil support\n");
2756 return WINED3DERR_NOTAVAILABLE;
2760 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2761 if (CheckRenderTargetCapability(adapter, adapter_format_desc, format_desc))
2763 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2764 } else {
2765 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2766 return WINED3DERR_NOTAVAILABLE;
2770 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2771 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2772 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
2774 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2775 } else {
2776 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2777 return WINED3DERR_NOTAVAILABLE;
2780 } else {
2781 TRACE_(d3d_caps)("[FAILED] - Not supported for plain surfaces\n");
2782 return WINED3DERR_NOTAVAILABLE;
2785 } else if(RType == WINED3DRTYPE_TEXTURE) {
2786 /* Texture allows:
2787 * - D3DUSAGE_AUTOGENMIPMAP
2788 * - D3DUSAGE_DEPTHSTENCIL
2789 * - D3DUSAGE_DMAP
2790 * - D3DUSAGE_DYNAMIC
2791 * - D3DUSAGE_NONSECURE (d3d9ex)
2792 * - D3DUSAGE_RENDERTARGET
2793 * - D3DUSAGE_SOFTWAREPROCESSING
2794 * - D3DUSAGE_TEXTAPI (d3d9ex)
2795 * - D3DUSAGE_QUERY_WRAPANDMIP
2798 if(SurfaceType != SURFACE_OPENGL) {
2799 TRACE("[FAILED]\n");
2800 return WINED3DERR_NOTAVAILABLE;
2803 /* Check if the texture format is around */
2804 if (CheckTextureCapability(adapter, DeviceType, format_desc))
2806 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
2807 /* Check for automatic mipmap generation support */
2808 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2809 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
2810 } else {
2811 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUTOGEN instead of D3D_OK */
2812 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
2816 /* Always report dynamic locking */
2817 if(Usage & WINED3DUSAGE_DYNAMIC)
2818 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2820 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2821 if (CheckRenderTargetCapability(adapter, adapter_format_desc, format_desc))
2823 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2824 } else {
2825 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2826 return WINED3DERR_NOTAVAILABLE;
2830 /* Always report software processing */
2831 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2832 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2834 /* Check QUERY_FILTER support */
2835 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2836 if (CheckFilterCapability(adapter, format_desc))
2838 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2839 } else {
2840 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2841 return WINED3DERR_NOTAVAILABLE;
2845 /* Check QUERY_LEGACYBUMPMAP support */
2846 if(Usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP) {
2847 if (CheckBumpMapCapability(adapter, DeviceType, format_desc))
2849 UsageCaps |= WINED3DUSAGE_QUERY_LEGACYBUMPMAP;
2850 } else {
2851 TRACE_(d3d_caps)("[FAILED] - No legacy bumpmap support\n");
2852 return WINED3DERR_NOTAVAILABLE;
2856 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2857 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2858 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
2860 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2861 } else {
2862 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2863 return WINED3DERR_NOTAVAILABLE;
2867 /* Check QUERY_SRGBREAD support */
2868 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2869 if (CheckSrgbReadCapability(adapter, format_desc))
2871 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2872 } else {
2873 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2874 return WINED3DERR_NOTAVAILABLE;
2878 /* Check QUERY_SRGBWRITE support */
2879 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2880 if (CheckSrgbWriteCapability(adapter, DeviceType, format_desc))
2882 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2883 } else {
2884 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2885 return WINED3DERR_NOTAVAILABLE;
2889 /* Check QUERY_VERTEXTEXTURE support */
2890 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2891 if (CheckVertexTextureCapability(adapter, format_desc))
2893 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2894 } else {
2895 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2896 return WINED3DERR_NOTAVAILABLE;
2900 /* Check QUERY_WRAPANDMIP support */
2901 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
2902 if (CheckWrapAndMipCapability(adapter, format_desc))
2904 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
2905 } else {
2906 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
2907 return WINED3DERR_NOTAVAILABLE;
2911 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
2912 if (CheckDepthStencilCapability(adapter, adapter_format_desc, format_desc))
2914 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
2915 } else {
2916 TRACE_(d3d_caps)("[FAILED] - No depth stencil support\n");
2917 return WINED3DERR_NOTAVAILABLE;
2920 } else {
2921 TRACE_(d3d_caps)("[FAILED] - Texture format not supported\n");
2922 return WINED3DERR_NOTAVAILABLE;
2924 } else if((RType == WINED3DRTYPE_VOLUME) || (RType == WINED3DRTYPE_VOLUMETEXTURE)) {
2925 /* Volume is to VolumeTexture what Surface is to Texture but its usage caps are not documented.
2926 * Most driver seem to offer (nearly) the same on Volume and VolumeTexture, so do that too.
2928 * Volumetexture allows:
2929 * - D3DUSAGE_DYNAMIC
2930 * - D3DUSAGE_NONSECURE (d3d9ex)
2931 * - D3DUSAGE_SOFTWAREPROCESSING
2932 * - D3DUSAGE_QUERY_WRAPANDMIP
2935 if(SurfaceType != SURFACE_OPENGL) {
2936 TRACE("[FAILED]\n");
2937 return WINED3DERR_NOTAVAILABLE;
2940 /* Check volume texture and volume usage caps */
2941 if(GL_SUPPORT(EXT_TEXTURE3D)) {
2942 if (!CheckTextureCapability(adapter, DeviceType, format_desc))
2944 TRACE_(d3d_caps)("[FAILED] - Format not supported\n");
2945 return WINED3DERR_NOTAVAILABLE;
2948 /* Always report dynamic locking */
2949 if(Usage & WINED3DUSAGE_DYNAMIC)
2950 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2952 /* Always report software processing */
2953 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2954 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2956 /* Check QUERY_FILTER support */
2957 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2958 if (CheckFilterCapability(adapter, format_desc))
2960 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2961 } else {
2962 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2963 return WINED3DERR_NOTAVAILABLE;
2967 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2968 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2969 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
2971 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2972 } else {
2973 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2974 return WINED3DERR_NOTAVAILABLE;
2978 /* Check QUERY_SRGBREAD support */
2979 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2980 if (CheckSrgbReadCapability(adapter, format_desc))
2982 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2983 } else {
2984 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2985 return WINED3DERR_NOTAVAILABLE;
2989 /* Check QUERY_SRGBWRITE support */
2990 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2991 if (CheckSrgbWriteCapability(adapter, DeviceType, format_desc))
2993 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2994 } else {
2995 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2996 return WINED3DERR_NOTAVAILABLE;
3000 /* Check QUERY_VERTEXTEXTURE support */
3001 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
3002 if (CheckVertexTextureCapability(adapter, format_desc))
3004 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
3005 } else {
3006 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
3007 return WINED3DERR_NOTAVAILABLE;
3011 /* Check QUERY_WRAPANDMIP support */
3012 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
3013 if (CheckWrapAndMipCapability(adapter, format_desc))
3015 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
3016 } else {
3017 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
3018 return WINED3DERR_NOTAVAILABLE;
3021 } else {
3022 TRACE_(d3d_caps)("[FAILED] - No volume texture support\n");
3023 return WINED3DERR_NOTAVAILABLE;
3026 /* Filter formats that need conversion; For one part, this conversion is unimplemented,
3027 * and volume textures are huge, so it would be a big performance hit. Unless we hit an
3028 * app needing one of those formats, don't advertize them to avoid leading apps into
3029 * temptation. The windows drivers don't support most of those formats on volumes anyway,
3030 * except of R32F.
3032 switch(CheckFormat) {
3033 case WINED3DFMT_P8:
3034 case WINED3DFMT_A4L4:
3035 case WINED3DFMT_R32_FLOAT:
3036 case WINED3DFMT_R16_FLOAT:
3037 case WINED3DFMT_X8L8V8U8:
3038 case WINED3DFMT_L6V5U5:
3039 case WINED3DFMT_R16G16_UNORM:
3040 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
3041 return WINED3DERR_NOTAVAILABLE;
3043 case WINED3DFMT_R8G8B8A8_SNORM:
3044 case WINED3DFMT_R16G16_SNORM:
3045 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
3046 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
3047 return WINED3DERR_NOTAVAILABLE;
3049 break;
3051 case WINED3DFMT_R8G8_SNORM:
3052 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
3053 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
3054 return WINED3DERR_NOTAVAILABLE;
3056 break;
3058 case WINED3DFMT_DXT1:
3059 case WINED3DFMT_DXT2:
3060 case WINED3DFMT_DXT3:
3061 case WINED3DFMT_DXT4:
3062 case WINED3DFMT_DXT5:
3063 /* The GL_EXT_texture_compression_s3tc spec requires that loading an s3tc
3064 * compressed texture results in an error. While the D3D refrast does
3065 * support s3tc volumes, at least the nvidia windows driver does not, so
3066 * we're free not to support this format.
3068 TRACE_(d3d_caps)("[FAILED] - DXTn does not support 3D textures\n");
3069 return WINED3DERR_NOTAVAILABLE;
3071 default:
3072 /* Do nothing, continue with checking the format below */
3073 break;
3075 } else if(RType == WINED3DRTYPE_BUFFER){
3076 /* For instance vertexbuffer/indexbuffer aren't supported yet because no Windows drivers seem to offer it */
3077 TRACE_(d3d_caps)("Unhandled resource type D3DRTYPE_INDEXBUFFER / D3DRTYPE_VERTEXBUFFER\n");
3078 return WINED3DERR_NOTAVAILABLE;
3081 /* This format is nothing special and it is supported perfectly.
3082 * However, ati and nvidia driver on windows do not mark this format as
3083 * supported (tested with the dxCapsViewer) and pretending to
3084 * support this format uncovers a bug in Battlefield 1942 (fonts are missing)
3085 * So do the same as Windows drivers and pretend not to support it on dx8 and 9
3086 * Enable it on dx7. It will need additional checking on dx10 when we support it.
3088 if(This->dxVersion > 7 && CheckFormat == WINED3DFMT_R8G8B8) {
3089 TRACE_(d3d_caps)("[FAILED]\n");
3090 return WINED3DERR_NOTAVAILABLE;
3093 /* When the UsageCaps exactly matches Usage return WINED3D_OK except for the situation in which
3094 * WINED3DUSAGE_AUTOGENMIPMAP isn't around, then WINED3DOK_NOAUTOGEN is returned if all the other
3095 * usage flags match. */
3096 if(UsageCaps == Usage) {
3097 return WINED3D_OK;
3098 } else if((UsageCaps == (Usage & ~WINED3DUSAGE_AUTOGENMIPMAP)) && (Usage & WINED3DUSAGE_AUTOGENMIPMAP)){
3099 return WINED3DOK_NOAUTOGEN;
3100 } else {
3101 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);
3102 return WINED3DERR_NOTAVAILABLE;
3106 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
3107 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
3108 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3110 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))\n",
3111 This,
3112 Adapter,
3113 DeviceType, debug_d3ddevicetype(DeviceType),
3114 SourceFormat, debug_d3dformat(SourceFormat),
3115 TargetFormat, debug_d3dformat(TargetFormat));
3116 return WINED3D_OK;
3119 static const shader_backend_t *select_shader_backend(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType)
3121 const shader_backend_t *ret;
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 (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) {
3127 ret = &glsl_shader_backend;
3128 } else if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) {
3129 ret = &arb_program_shader_backend;
3130 } else {
3131 ret = &none_shader_backend;
3133 return ret;
3136 static const struct fragment_pipeline *select_fragment_implementation(struct WineD3DAdapter *adapter,
3137 WINED3DDEVTYPE DeviceType)
3139 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
3140 int vs_selected_mode;
3141 int ps_selected_mode;
3143 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
3144 if((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
3145 return &arbfp_fragment_pipeline;
3146 } else if(ps_selected_mode == SHADER_ATI) {
3147 return &atifs_fragment_pipeline;
3148 } else if(GL_SUPPORT(NV_REGISTER_COMBINERS) && GL_SUPPORT(NV_TEXTURE_SHADER2)) {
3149 return &nvts_fragment_pipeline;
3150 } else if(GL_SUPPORT(NV_REGISTER_COMBINERS)) {
3151 return &nvrc_fragment_pipeline;
3152 } else {
3153 return &ffp_fragment_pipeline;
3157 static const struct blit_shader *select_blit_implementation(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType)
3159 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
3160 int vs_selected_mode;
3161 int ps_selected_mode;
3163 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
3164 if((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
3165 return &arbfp_blit;
3166 } else {
3167 return &ffp_blit;
3171 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
3172 subset of a D3DCAPS9 structure. However, it has to come via a void *
3173 as the d3d8 interface cannot import the d3d9 header */
3174 static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
3176 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3177 struct WineD3DAdapter *adapter = &This->adapters[Adapter];
3178 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
3179 int vs_selected_mode;
3180 int ps_selected_mode;
3181 struct shader_caps shader_caps;
3182 struct fragment_caps fragment_caps;
3183 const shader_backend_t *shader_backend;
3184 const struct fragment_pipeline *frag_pipeline = NULL;
3185 DWORD ckey_caps, blit_caps, fx_caps;
3187 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
3189 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
3190 return WINED3DERR_INVALIDCALL;
3193 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
3195 /* This function should *not* be modifying GL caps
3196 * TODO: move the functionality where it belongs */
3197 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &adapter->gl_info);
3199 /* ------------------------------------------------
3200 The following fields apply to both d3d8 and d3d9
3201 ------------------------------------------------ */
3202 pCaps->DeviceType = (DeviceType == WINED3DDEVTYPE_HAL) ? WINED3DDEVTYPE_HAL : WINED3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
3203 pCaps->AdapterOrdinal = Adapter;
3205 pCaps->Caps = 0;
3206 pCaps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
3207 WINED3DCAPS2_FULLSCREENGAMMA |
3208 WINED3DCAPS2_DYNAMICTEXTURES;
3209 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
3210 pCaps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
3213 pCaps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
3214 WINED3DCAPS3_COPY_TO_VIDMEM |
3215 WINED3DCAPS3_COPY_TO_SYSTEMMEM;
3217 pCaps->PresentationIntervals = WINED3DPRESENT_INTERVAL_IMMEDIATE |
3218 WINED3DPRESENT_INTERVAL_ONE;
3220 pCaps->CursorCaps = WINED3DCURSORCAPS_COLOR |
3221 WINED3DCURSORCAPS_LOWRES;
3223 pCaps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
3224 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
3225 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
3226 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
3227 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
3228 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
3229 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
3230 WINED3DDEVCAPS_PUREDEVICE |
3231 WINED3DDEVCAPS_HWRASTERIZATION |
3232 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
3233 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
3234 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
3235 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
3236 WINED3DDEVCAPS_DRAWPRIMITIVES2EX |
3237 WINED3DDEVCAPS_RTPATCHES;
3239 pCaps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
3240 WINED3DPMISCCAPS_CULLCCW |
3241 WINED3DPMISCCAPS_CULLCW |
3242 WINED3DPMISCCAPS_COLORWRITEENABLE |
3243 WINED3DPMISCCAPS_CLIPTLVERTS |
3244 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
3245 WINED3DPMISCCAPS_MASKZ |
3246 WINED3DPMISCCAPS_BLENDOP |
3247 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING;
3248 /* TODO:
3249 WINED3DPMISCCAPS_NULLREFERENCE
3250 WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS
3251 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
3252 WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
3253 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
3255 if(GL_SUPPORT(EXT_BLEND_EQUATION_SEPARATE) && GL_SUPPORT(EXT_BLEND_FUNC_SEPARATE))
3256 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
3258 pCaps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
3259 WINED3DPRASTERCAPS_PAT |
3260 WINED3DPRASTERCAPS_WFOG |
3261 WINED3DPRASTERCAPS_ZFOG |
3262 WINED3DPRASTERCAPS_FOGVERTEX |
3263 WINED3DPRASTERCAPS_FOGTABLE |
3264 WINED3DPRASTERCAPS_STIPPLE |
3265 WINED3DPRASTERCAPS_SUBPIXEL |
3266 WINED3DPRASTERCAPS_ZTEST |
3267 WINED3DPRASTERCAPS_SCISSORTEST |
3268 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
3269 WINED3DPRASTERCAPS_DEPTHBIAS;
3271 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3272 pCaps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY |
3273 WINED3DPRASTERCAPS_ZBIAS |
3274 WINED3DPRASTERCAPS_MIPMAPLODBIAS;
3276 if(GL_SUPPORT(NV_FOG_DISTANCE)) {
3277 pCaps->RasterCaps |= WINED3DPRASTERCAPS_FOGRANGE;
3279 /* FIXME Add:
3280 WINED3DPRASTERCAPS_COLORPERSPECTIVE
3281 WINED3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
3282 WINED3DPRASTERCAPS_ANTIALIASEDGES
3283 WINED3DPRASTERCAPS_ZBUFFERLESSHSR
3284 WINED3DPRASTERCAPS_WBUFFER */
3286 pCaps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
3287 WINED3DPCMPCAPS_EQUAL |
3288 WINED3DPCMPCAPS_GREATER |
3289 WINED3DPCMPCAPS_GREATEREQUAL |
3290 WINED3DPCMPCAPS_LESS |
3291 WINED3DPCMPCAPS_LESSEQUAL |
3292 WINED3DPCMPCAPS_NEVER |
3293 WINED3DPCMPCAPS_NOTEQUAL;
3295 pCaps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
3296 WINED3DPBLENDCAPS_BOTHSRCALPHA |
3297 WINED3DPBLENDCAPS_DESTALPHA |
3298 WINED3DPBLENDCAPS_DESTCOLOR |
3299 WINED3DPBLENDCAPS_INVDESTALPHA |
3300 WINED3DPBLENDCAPS_INVDESTCOLOR |
3301 WINED3DPBLENDCAPS_INVSRCALPHA |
3302 WINED3DPBLENDCAPS_INVSRCCOLOR |
3303 WINED3DPBLENDCAPS_ONE |
3304 WINED3DPBLENDCAPS_SRCALPHA |
3305 WINED3DPBLENDCAPS_SRCALPHASAT |
3306 WINED3DPBLENDCAPS_SRCCOLOR |
3307 WINED3DPBLENDCAPS_ZERO;
3309 pCaps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
3310 WINED3DPBLENDCAPS_DESTCOLOR |
3311 WINED3DPBLENDCAPS_INVDESTALPHA |
3312 WINED3DPBLENDCAPS_INVDESTCOLOR |
3313 WINED3DPBLENDCAPS_INVSRCALPHA |
3314 WINED3DPBLENDCAPS_INVSRCCOLOR |
3315 WINED3DPBLENDCAPS_ONE |
3316 WINED3DPBLENDCAPS_SRCALPHA |
3317 WINED3DPBLENDCAPS_SRCCOLOR |
3318 WINED3DPBLENDCAPS_ZERO;
3319 /* NOTE: WINED3DPBLENDCAPS_SRCALPHASAT is not supported as dest blend factor,
3320 * according to the glBlendFunc manpage
3322 * WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA are
3323 * legacy settings for srcblend only
3326 if( GL_SUPPORT(EXT_BLEND_COLOR)) {
3327 pCaps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
3328 pCaps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
3332 pCaps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
3333 WINED3DPCMPCAPS_EQUAL |
3334 WINED3DPCMPCAPS_GREATER |
3335 WINED3DPCMPCAPS_GREATEREQUAL |
3336 WINED3DPCMPCAPS_LESS |
3337 WINED3DPCMPCAPS_LESSEQUAL |
3338 WINED3DPCMPCAPS_NEVER |
3339 WINED3DPCMPCAPS_NOTEQUAL;
3341 pCaps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
3342 WINED3DPSHADECAPS_COLORGOURAUDRGB |
3343 WINED3DPSHADECAPS_ALPHAFLATBLEND |
3344 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
3345 WINED3DPSHADECAPS_COLORFLATRGB |
3346 WINED3DPSHADECAPS_FOGFLAT |
3347 WINED3DPSHADECAPS_FOGGOURAUD |
3348 WINED3DPSHADECAPS_SPECULARFLATRGB;
3350 pCaps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
3351 WINED3DPTEXTURECAPS_ALPHAPALETTE |
3352 WINED3DPTEXTURECAPS_TRANSPARENCY |
3353 WINED3DPTEXTURECAPS_BORDER |
3354 WINED3DPTEXTURECAPS_MIPMAP |
3355 WINED3DPTEXTURECAPS_PROJECTED |
3356 WINED3DPTEXTURECAPS_PERSPECTIVE;
3358 if( !GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
3359 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
3360 WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
3363 if( GL_SUPPORT(EXT_TEXTURE3D)) {
3364 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP |
3365 WINED3DPTEXTURECAPS_MIPVOLUMEMAP |
3366 WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
3369 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
3370 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP |
3371 WINED3DPTEXTURECAPS_MIPCUBEMAP |
3372 WINED3DPTEXTURECAPS_CUBEMAP_POW2;
3376 pCaps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3377 WINED3DPTFILTERCAPS_MAGFPOINT |
3378 WINED3DPTFILTERCAPS_MINFLINEAR |
3379 WINED3DPTFILTERCAPS_MINFPOINT |
3380 WINED3DPTFILTERCAPS_MIPFLINEAR |
3381 WINED3DPTFILTERCAPS_MIPFPOINT |
3382 WINED3DPTFILTERCAPS_LINEAR |
3383 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3384 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3385 WINED3DPTFILTERCAPS_MIPLINEAR |
3386 WINED3DPTFILTERCAPS_MIPNEAREST |
3387 WINED3DPTFILTERCAPS_NEAREST;
3389 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3390 pCaps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
3391 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
3394 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
3395 pCaps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3396 WINED3DPTFILTERCAPS_MAGFPOINT |
3397 WINED3DPTFILTERCAPS_MINFLINEAR |
3398 WINED3DPTFILTERCAPS_MINFPOINT |
3399 WINED3DPTFILTERCAPS_MIPFLINEAR |
3400 WINED3DPTFILTERCAPS_MIPFPOINT |
3401 WINED3DPTFILTERCAPS_LINEAR |
3402 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3403 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3404 WINED3DPTFILTERCAPS_MIPLINEAR |
3405 WINED3DPTFILTERCAPS_MIPNEAREST |
3406 WINED3DPTFILTERCAPS_NEAREST;
3408 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3409 pCaps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
3410 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
3412 } else
3413 pCaps->CubeTextureFilterCaps = 0;
3415 if (GL_SUPPORT(EXT_TEXTURE3D)) {
3416 pCaps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3417 WINED3DPTFILTERCAPS_MAGFPOINT |
3418 WINED3DPTFILTERCAPS_MINFLINEAR |
3419 WINED3DPTFILTERCAPS_MINFPOINT |
3420 WINED3DPTFILTERCAPS_MIPFLINEAR |
3421 WINED3DPTFILTERCAPS_MIPFPOINT |
3422 WINED3DPTFILTERCAPS_LINEAR |
3423 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3424 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3425 WINED3DPTFILTERCAPS_MIPLINEAR |
3426 WINED3DPTFILTERCAPS_MIPNEAREST |
3427 WINED3DPTFILTERCAPS_NEAREST;
3428 } else
3429 pCaps->VolumeTextureFilterCaps = 0;
3431 pCaps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
3432 WINED3DPTADDRESSCAPS_CLAMP |
3433 WINED3DPTADDRESSCAPS_WRAP;
3435 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
3436 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
3438 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
3439 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
3441 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
3442 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
3445 if (GL_SUPPORT(EXT_TEXTURE3D)) {
3446 pCaps->VolumeTextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
3447 WINED3DPTADDRESSCAPS_CLAMP |
3448 WINED3DPTADDRESSCAPS_WRAP;
3449 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
3450 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
3452 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
3453 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
3455 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
3456 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
3458 } else
3459 pCaps->VolumeTextureAddressCaps = 0;
3461 pCaps->LineCaps = WINED3DLINECAPS_TEXTURE |
3462 WINED3DLINECAPS_ZTEST |
3463 WINED3DLINECAPS_BLEND |
3464 WINED3DLINECAPS_ALPHACMP |
3465 WINED3DLINECAPS_FOG;
3466 /* WINED3DLINECAPS_ANTIALIAS is not supported on Windows, and dx and gl seem to have a different
3467 * idea how generating the smoothing alpha values works; the result is different
3470 pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
3471 pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
3473 if(GL_SUPPORT(EXT_TEXTURE3D))
3474 pCaps->MaxVolumeExtent = GL_LIMITS(texture3d_size);
3475 else
3476 pCaps->MaxVolumeExtent = 0;
3478 pCaps->MaxTextureRepeat = 32768;
3479 pCaps->MaxTextureAspectRatio = GL_LIMITS(texture_size);
3480 pCaps->MaxVertexW = 1.0;
3482 pCaps->GuardBandLeft = 0;
3483 pCaps->GuardBandTop = 0;
3484 pCaps->GuardBandRight = 0;
3485 pCaps->GuardBandBottom = 0;
3487 pCaps->ExtentsAdjust = 0;
3489 pCaps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
3490 WINED3DSTENCILCAPS_INCRSAT |
3491 WINED3DSTENCILCAPS_INVERT |
3492 WINED3DSTENCILCAPS_KEEP |
3493 WINED3DSTENCILCAPS_REPLACE |
3494 WINED3DSTENCILCAPS_ZERO;
3495 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
3496 pCaps->StencilCaps |= WINED3DSTENCILCAPS_DECR |
3497 WINED3DSTENCILCAPS_INCR;
3499 if ( This->dxVersion > 8 &&
3500 ( GL_SUPPORT(EXT_STENCIL_TWO_SIDE) ||
3501 GL_SUPPORT(ATI_SEPARATE_STENCIL) ) ) {
3502 pCaps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
3505 pCaps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
3507 pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
3508 pCaps->MaxActiveLights = GL_LIMITS(lights);
3510 pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
3511 pCaps->MaxVertexBlendMatrixIndex = 0;
3513 pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
3514 pCaps->MaxPointSize = GL_LIMITS(pointsize);
3517 pCaps->VertexProcessingCaps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
3518 WINED3DVTXPCAPS_MATERIALSOURCE7 |
3519 WINED3DVTXPCAPS_POSITIONALLIGHTS |
3520 WINED3DVTXPCAPS_LOCALVIEWER |
3521 WINED3DVTXPCAPS_VERTEXFOG |
3522 WINED3DVTXPCAPS_TEXGEN;
3523 /* FIXME: Add
3524 D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
3526 pCaps->MaxPrimitiveCount = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
3527 pCaps->MaxVertexIndex = 0xFFFFF;
3528 pCaps->MaxStreams = MAX_STREAMS;
3529 pCaps->MaxStreamStride = 1024;
3531 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
3532 pCaps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET |
3533 WINED3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
3534 pCaps->MaxNpatchTessellationLevel = 0;
3535 pCaps->MasterAdapterOrdinal = 0;
3536 pCaps->AdapterOrdinalInGroup = 0;
3537 pCaps->NumberOfAdaptersInGroup = 1;
3539 pCaps->NumSimultaneousRTs = GL_LIMITS(buffers);
3541 pCaps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
3542 WINED3DPTFILTERCAPS_MAGFPOINT |
3543 WINED3DPTFILTERCAPS_MINFLINEAR |
3544 WINED3DPTFILTERCAPS_MAGFLINEAR;
3545 pCaps->VertexTextureFilterCaps = 0;
3547 memset(&shader_caps, 0, sizeof(shader_caps));
3548 shader_backend = select_shader_backend(adapter, DeviceType);
3549 shader_backend->shader_get_caps(DeviceType, &adapter->gl_info, &shader_caps);
3551 memset(&fragment_caps, 0, sizeof(fragment_caps));
3552 frag_pipeline = select_fragment_implementation(adapter, DeviceType);
3553 frag_pipeline->get_caps(DeviceType, &adapter->gl_info, &fragment_caps);
3555 /* Add shader misc caps. Only some of them belong to the shader parts of the pipeline */
3556 pCaps->PrimitiveMiscCaps |= fragment_caps.PrimitiveMiscCaps;
3558 /* This takes care for disabling vertex shader or pixel shader caps while leaving the other one enabled.
3559 * Ignore shader model capabilities if disabled in config
3561 if(vs_selected_mode == SHADER_NONE) {
3562 TRACE_(d3d_caps)("Vertex shader disabled in config, reporting version 0.0\n");
3563 pCaps->VertexShaderVersion = WINED3DVS_VERSION(0,0);
3564 pCaps->MaxVertexShaderConst = 0;
3565 } else {
3566 pCaps->VertexShaderVersion = shader_caps.VertexShaderVersion;
3567 pCaps->MaxVertexShaderConst = shader_caps.MaxVertexShaderConst;
3570 if(ps_selected_mode == SHADER_NONE) {
3571 TRACE_(d3d_caps)("Pixel shader disabled in config, reporting version 0.0\n");
3572 pCaps->PixelShaderVersion = WINED3DPS_VERSION(0,0);
3573 pCaps->PixelShader1xMaxValue = 0.0;
3574 } else {
3575 pCaps->PixelShaderVersion = shader_caps.PixelShaderVersion;
3576 pCaps->PixelShader1xMaxValue = shader_caps.PixelShader1xMaxValue;
3579 pCaps->TextureOpCaps = fragment_caps.TextureOpCaps;
3580 pCaps->MaxTextureBlendStages = fragment_caps.MaxTextureBlendStages;
3581 pCaps->MaxSimultaneousTextures = fragment_caps.MaxSimultaneousTextures;
3583 pCaps->VS20Caps = shader_caps.VS20Caps;
3584 pCaps->MaxVShaderInstructionsExecuted = shader_caps.MaxVShaderInstructionsExecuted;
3585 pCaps->MaxVertexShader30InstructionSlots= shader_caps.MaxVertexShader30InstructionSlots;
3586 pCaps->PS20Caps = shader_caps.PS20Caps;
3587 pCaps->MaxPShaderInstructionsExecuted = shader_caps.MaxPShaderInstructionsExecuted;
3588 pCaps->MaxPixelShader30InstructionSlots = shader_caps.MaxPixelShader30InstructionSlots;
3590 /* The following caps are shader specific, but they are things we cannot detect, or which
3591 * are the same among all shader models. So to avoid code duplication set the shader version
3592 * specific, but otherwise constant caps here
3594 if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(3,0)) {
3595 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
3596 use the VS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum VS3.0 value. */
3597 pCaps->VS20Caps.Caps = WINED3DVS20CAPS_PREDICATION;
3598 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
3599 pCaps->VS20Caps.NumTemps = max(32, adapter->gl_info.vs_arb_max_temps);
3600 pCaps->VS20Caps.StaticFlowControlDepth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH ; /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
3602 pCaps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
3603 pCaps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.vs_arb_max_instructions);
3604 } else if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(2,0)) {
3605 pCaps->VS20Caps.Caps = 0;
3606 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
3607 pCaps->VS20Caps.NumTemps = max(12, adapter->gl_info.vs_arb_max_temps);
3608 pCaps->VS20Caps.StaticFlowControlDepth = 1;
3610 pCaps->MaxVShaderInstructionsExecuted = 65535;
3611 pCaps->MaxVertexShader30InstructionSlots = 0;
3612 } else { /* VS 1.x */
3613 pCaps->VS20Caps.Caps = 0;
3614 pCaps->VS20Caps.DynamicFlowControlDepth = 0;
3615 pCaps->VS20Caps.NumTemps = 0;
3616 pCaps->VS20Caps.StaticFlowControlDepth = 0;
3618 pCaps->MaxVShaderInstructionsExecuted = 0;
3619 pCaps->MaxVertexShader30InstructionSlots = 0;
3622 if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(3,0)) {
3623 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
3624 use the PS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum PS 3.0 value. */
3626 /* 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 */
3627 pCaps->PS20Caps.Caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
3628 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
3629 WINED3DPS20CAPS_PREDICATION |
3630 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
3631 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
3632 pCaps->PS20Caps.DynamicFlowControlDepth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
3633 pCaps->PS20Caps.NumTemps = max(32, adapter->gl_info.ps_arb_max_temps);
3634 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
3635 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
3637 pCaps->MaxPShaderInstructionsExecuted = 65535;
3638 pCaps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS, adapter->gl_info.ps_arb_max_instructions);
3639 } else if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(2,0)) {
3640 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
3641 pCaps->PS20Caps.Caps = 0;
3642 pCaps->PS20Caps.DynamicFlowControlDepth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
3643 pCaps->PS20Caps.NumTemps = max(12, adapter->gl_info.ps_arb_max_temps);
3644 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
3645 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
3647 pCaps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
3648 pCaps->MaxPixelShader30InstructionSlots = 0;
3649 } else { /* PS 1.x */
3650 pCaps->PS20Caps.Caps = 0;
3651 pCaps->PS20Caps.DynamicFlowControlDepth = 0;
3652 pCaps->PS20Caps.NumTemps = 0;
3653 pCaps->PS20Caps.StaticFlowControlDepth = 0;
3654 pCaps->PS20Caps.NumInstructionSlots = 0;
3656 pCaps->MaxPShaderInstructionsExecuted = 0;
3657 pCaps->MaxPixelShader30InstructionSlots = 0;
3660 if(pCaps->VertexShaderVersion >= WINED3DVS_VERSION(2,0)) {
3661 /* OpenGL supports all the formats below, perhaps not always
3662 * without conversion, but it supports them.
3663 * Further GLSL doesn't seem to have an official unsigned type so
3664 * don't advertise it yet as I'm not sure how we handle it.
3665 * We might need to add some clamping in the shader engine to
3666 * support it.
3667 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
3668 pCaps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
3669 WINED3DDTCAPS_UBYTE4N |
3670 WINED3DDTCAPS_SHORT2N |
3671 WINED3DDTCAPS_SHORT4N;
3672 if (GL_SUPPORT(ARB_HALF_FLOAT_VERTEX)) {
3673 pCaps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
3674 WINED3DDTCAPS_FLOAT16_4;
3676 } else
3677 pCaps->DeclTypes = 0;
3679 /* Set DirectDraw helper Caps */
3680 ckey_caps = WINEDDCKEYCAPS_DESTBLT |
3681 WINEDDCKEYCAPS_SRCBLT;
3682 fx_caps = WINEDDFXCAPS_BLTALPHA |
3683 WINEDDFXCAPS_BLTMIRRORLEFTRIGHT |
3684 WINEDDFXCAPS_BLTMIRRORUPDOWN |
3685 WINEDDFXCAPS_BLTROTATION90 |
3686 WINEDDFXCAPS_BLTSHRINKX |
3687 WINEDDFXCAPS_BLTSHRINKXN |
3688 WINEDDFXCAPS_BLTSHRINKY |
3689 WINEDDFXCAPS_BLTSHRINKXN |
3690 WINEDDFXCAPS_BLTSTRETCHX |
3691 WINEDDFXCAPS_BLTSTRETCHXN |
3692 WINEDDFXCAPS_BLTSTRETCHY |
3693 WINEDDFXCAPS_BLTSTRETCHYN;
3694 blit_caps = WINEDDCAPS_BLT |
3695 WINEDDCAPS_BLTCOLORFILL |
3696 WINEDDCAPS_BLTDEPTHFILL |
3697 WINEDDCAPS_BLTSTRETCH |
3698 WINEDDCAPS_CANBLTSYSMEM |
3699 WINEDDCAPS_CANCLIP |
3700 WINEDDCAPS_CANCLIPSTRETCHED |
3701 WINEDDCAPS_COLORKEY |
3702 WINEDDCAPS_COLORKEYHWASSIST |
3703 WINEDDCAPS_ALIGNBOUNDARYSRC;
3705 /* Fill the ddraw caps structure */
3706 pCaps->DirectDrawCaps.Caps = WINEDDCAPS_GDI |
3707 WINEDDCAPS_PALETTE |
3708 blit_caps;
3709 pCaps->DirectDrawCaps.Caps2 = WINEDDCAPS2_CERTIFIED |
3710 WINEDDCAPS2_NOPAGELOCKREQUIRED |
3711 WINEDDCAPS2_PRIMARYGAMMA |
3712 WINEDDCAPS2_WIDESURFACES |
3713 WINEDDCAPS2_CANRENDERWINDOWED;
3714 pCaps->DirectDrawCaps.SVBCaps = blit_caps;
3715 pCaps->DirectDrawCaps.SVBCKeyCaps = ckey_caps;
3716 pCaps->DirectDrawCaps.SVBFXCaps = fx_caps;
3717 pCaps->DirectDrawCaps.VSBCaps = blit_caps;
3718 pCaps->DirectDrawCaps.VSBCKeyCaps = ckey_caps;
3719 pCaps->DirectDrawCaps.VSBFXCaps = fx_caps;
3720 pCaps->DirectDrawCaps.SSBCaps = blit_caps;
3721 pCaps->DirectDrawCaps.SSBCKeyCaps = ckey_caps;
3722 pCaps->DirectDrawCaps.SSBFXCaps = fx_caps;
3724 pCaps->DirectDrawCaps.ddsCaps = WINEDDSCAPS_ALPHA |
3725 WINEDDSCAPS_BACKBUFFER |
3726 WINEDDSCAPS_FLIP |
3727 WINEDDSCAPS_FRONTBUFFER |
3728 WINEDDSCAPS_OFFSCREENPLAIN |
3729 WINEDDSCAPS_PALETTE |
3730 WINEDDSCAPS_PRIMARYSURFACE |
3731 WINEDDSCAPS_SYSTEMMEMORY |
3732 WINEDDSCAPS_VIDEOMEMORY |
3733 WINEDDSCAPS_VISIBLE;
3734 pCaps->DirectDrawCaps.StrideAlign = DDRAW_PITCH_ALIGNMENT;
3736 /* Set D3D caps if OpenGL is available. */
3737 if (adapter->opengl)
3739 pCaps->DirectDrawCaps.ddsCaps |=WINEDDSCAPS_3DDEVICE |
3740 WINEDDSCAPS_MIPMAP |
3741 WINEDDSCAPS_TEXTURE |
3742 WINEDDSCAPS_ZBUFFER;
3743 pCaps->DirectDrawCaps.Caps |= WINEDDCAPS_3D;
3746 return WINED3D_OK;
3749 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
3750 and fields being inserted in the middle, a new structure is used in place */
3751 static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter,
3752 WINED3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviourFlags, IUnknown *parent,
3753 IWineD3DDeviceParent *device_parent, IWineD3DDevice **ppReturnedDeviceInterface)
3755 IWineD3DDeviceImpl *object = NULL;
3756 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3757 struct WineD3DAdapter *adapter = &This->adapters[Adapter];
3758 WINED3DDISPLAYMODE mode;
3759 const struct fragment_pipeline *frag_pipeline = NULL;
3760 int i;
3761 struct fragment_caps ffp_caps;
3762 struct shader_caps shader_caps;
3763 HRESULT hr;
3765 /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
3766 * number and create a device without a 3D adapter for 2D only operation.
3768 if (IWineD3D_GetAdapterCount(iface) && Adapter >= IWineD3D_GetAdapterCount(iface)) {
3769 return WINED3DERR_INVALIDCALL;
3772 /* Create a WineD3DDevice object */
3773 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
3774 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
3775 TRACE("Created WineD3DDevice object @ %p\n", object);
3776 if (NULL == object) {
3777 return WINED3DERR_OUTOFVIDEOMEMORY;
3780 /* Set up initial COM information */
3781 object->lpVtbl = &IWineD3DDevice_Vtbl;
3782 object->ref = 1;
3783 object->wineD3D = iface;
3784 object->adapter = This->adapter_count ? adapter : NULL;
3785 IWineD3D_AddRef(object->wineD3D);
3786 object->parent = parent;
3787 object->device_parent = device_parent;
3788 list_init(&object->resources);
3789 list_init(&object->shaders);
3791 if(This->dxVersion == 7) {
3792 object->surface_alignment = DDRAW_PITCH_ALIGNMENT;
3793 } else {
3794 object->surface_alignment = D3D8_PITCH_ALIGNMENT;
3796 object->posFixup[0] = 1.0; /* This is needed to get the x coord unmodified through a MAD */
3798 /* Set the state up as invalid until the device is fully created */
3799 object->state = WINED3DERR_DRIVERINTERNALERROR;
3801 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %x, RetDevInt: %p)\n", This, Adapter, DeviceType,
3802 hFocusWindow, BehaviourFlags, ppReturnedDeviceInterface);
3804 /* Save the creation parameters */
3805 object->createParms.AdapterOrdinal = Adapter;
3806 object->createParms.DeviceType = DeviceType;
3807 object->createParms.hFocusWindow = hFocusWindow;
3808 object->createParms.BehaviorFlags = BehaviourFlags;
3810 /* Initialize other useful values */
3811 object->adapterNo = Adapter;
3812 object->devType = DeviceType;
3814 select_shader_mode(&adapter->gl_info, DeviceType,
3815 &object->ps_selected_mode, &object->vs_selected_mode);
3816 object->shader_backend = select_shader_backend(adapter, DeviceType);
3818 memset(&shader_caps, 0, sizeof(shader_caps));
3819 object->shader_backend->shader_get_caps(DeviceType, &adapter->gl_info, &shader_caps);
3820 object->d3d_vshader_constantF = shader_caps.MaxVertexShaderConst;
3821 object->d3d_pshader_constantF = shader_caps.MaxPixelShaderConst;
3822 object->vs_clipping = shader_caps.VSClipping;
3824 memset(&ffp_caps, 0, sizeof(ffp_caps));
3825 frag_pipeline = select_fragment_implementation(adapter, DeviceType);
3826 object->frag_pipe = frag_pipeline;
3827 frag_pipeline->get_caps(DeviceType, &adapter->gl_info, &ffp_caps);
3828 object->max_ffp_textures = ffp_caps.MaxSimultaneousTextures;
3829 object->max_ffp_texture_stages = ffp_caps.MaxTextureBlendStages;
3830 hr = compile_state_table(object->StateTable, object->multistate_funcs, &adapter->gl_info,
3831 ffp_vertexstate_template, frag_pipeline, misc_state_template);
3833 if (FAILED(hr)) {
3834 IWineD3D_Release(object->wineD3D);
3835 HeapFree(GetProcessHeap(), 0, object);
3837 return hr;
3840 object->blitter = select_blit_implementation(adapter, DeviceType);
3842 /* set the state of the device to valid */
3843 object->state = WINED3D_OK;
3845 /* Get the initial screen setup for ddraw */
3846 IWineD3DImpl_GetAdapterDisplayMode(iface, Adapter, &mode);
3848 object->ddraw_width = mode.Width;
3849 object->ddraw_height = mode.Height;
3850 object->ddraw_format = mode.Format;
3852 for(i = 0; i < PATCHMAP_SIZE; i++) {
3853 list_init(&object->patches[i]);
3856 IWineD3DDeviceParent_WineD3DDeviceCreated(device_parent, *ppReturnedDeviceInterface);
3858 return WINED3D_OK;
3861 static HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
3862 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3863 IUnknown_AddRef(This->parent);
3864 *pParent = This->parent;
3865 return WINED3D_OK;
3868 ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface) {
3869 IUnknown* surfaceParent;
3870 TRACE("(%p) call back\n", pSurface);
3872 /* Now, release the parent, which will take care of cleaning up the surface for us */
3873 IWineD3DSurface_GetParent(pSurface, &surfaceParent);
3874 IUnknown_Release(surfaceParent);
3875 return IUnknown_Release(surfaceParent);
3878 ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pVolume) {
3879 IUnknown* volumeParent;
3880 TRACE("(%p) call back\n", pVolume);
3882 /* Now, release the parent, which will take care of cleaning up the volume for us */
3883 IWineD3DVolume_GetParent(pVolume, &volumeParent);
3884 IUnknown_Release(volumeParent);
3885 return IUnknown_Release(volumeParent);
3888 static BOOL match_apple(const WineD3D_GL_Info *gl_info)
3890 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
3891 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
3892 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
3894 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
3895 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
3896 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
3897 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
3898 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
3899 * the chance that other implementations support them is rather small since Win32 QuickTime uses
3900 * DirectDraw, not OpenGL.
3902 if(gl_info->supported[APPLE_FENCE] &&
3903 gl_info->supported[APPLE_CLIENT_STORAGE] &&
3904 gl_info->supported[APPLE_FLUSH_RENDER] &&
3905 gl_info->supported[APPLE_YCBCR_422]) {
3906 TRACE_(d3d_caps)("GL_APPLE_fence, GL_APPLE_client_storage, GL_APPLE_flush_render and GL_ycbcr_422 are supported\n");
3907 TRACE_(d3d_caps)("Activating MacOS fixups\n");
3908 return TRUE;
3909 } else {
3910 TRACE_(d3d_caps)("Apple extensions are not supported\n");
3911 TRACE_(d3d_caps)("Not activating MacOS fixups\n");
3912 return FALSE;
3916 static void test_pbo_functionality(WineD3D_GL_Info *gl_info) {
3917 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
3918 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
3919 * all the texture. This function detects this bug by its symptom and disables PBOs
3920 * if the test fails.
3922 * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
3923 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
3924 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
3925 * read back is compared to the original. If they are equal PBOs are assumed to work,
3926 * otherwise the PBO extension is disabled.
3928 GLuint texture, pbo;
3929 static const unsigned int pattern[] = {
3930 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
3931 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
3932 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
3933 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
3935 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
3937 if(!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) {
3938 /* No PBO -> No point in testing them */
3939 return;
3942 ENTER_GL();
3944 while(glGetError());
3945 glGenTextures(1, &texture);
3946 glBindTexture(GL_TEXTURE_2D, texture);
3948 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
3949 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
3950 checkGLcall("Specifying the PBO test texture\n");
3952 GL_EXTCALL(glGenBuffersARB(1, &pbo));
3953 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
3954 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
3955 checkGLcall("Specifying the PBO test pbo\n");
3957 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
3958 checkGLcall("Loading the PBO test texture\n");
3960 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
3961 glFinish(); /* just to be sure */
3963 memset(check, 0, sizeof(check));
3964 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
3965 checkGLcall("Reading back the PBO test texture\n");
3967 glDeleteTextures(1, &texture);
3968 GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
3969 checkGLcall("PBO test cleanup\n");
3971 LEAVE_GL();
3973 if(memcmp(check, pattern, sizeof(check)) != 0) {
3974 WARN_(d3d_caps)("PBO test failed, read back data doesn't match original\n");
3975 WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance\n");
3976 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
3977 } else {
3978 TRACE_(d3d_caps)("PBO test successful\n");
3982 /* Certain applications(Steam) complain if we report an outdated driver version. In general,
3983 * reporting a driver version is moot because we are not the Windows driver, and we have different
3984 * bugs, features, etc.
3986 * If a card is not found in this table, the gl driver version is reported
3988 struct driver_version_information {
3989 WORD vendor; /* reported PCI card vendor ID */
3990 WORD card; /* reported PCI card device ID */
3991 const char *description; /* Description of the card e.g. NVIDIA RIVA TNT */
3992 WORD hipart_hi, hipart_lo; /* driver hiword to report */
3993 WORD lopart_hi, lopart_lo; /* driver loword to report */
3996 static const struct driver_version_information driver_version_table[] = {
3997 /* Nvidia drivers. Geforce6 and newer cards are supported by the current driver (180.x)
3998 * 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
3999 * Geforce2MX/3/4 up to 96.x - driver uses numbering 9.6.8.9 for 96.89
4000 * TNT/Geforce1/2 up to 71.x - driver uses numbering 7.1.8.6 for 71.86
4002 * All version numbers used below are from the Linux nvidia drivers.
4004 {VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT, "NVIDIA RIVA TNT", 7, 1, 8, 6 },
4005 {VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT2, "NVIDIA RIVA TNT2/TNT2 Pro", 7, 1, 8, 6 },
4006 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE, "NVIDIA GeForce 256", 7, 1, 8, 6 },
4007 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2_MX, "NVIDIA GeForce2 MX/MX 400", 9, 6, 4, 3 },
4008 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2, "NVIDIA GeForce2 GTS/GeForce2 Pro", 7, 1, 8, 6 },
4009 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE3, "NVIDIA GeForce3", 9, 6, 4, 3 },
4010 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_MX, "NVIDIA GeForce4 MX 460", 9, 6, 4, 3 },
4011 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_TI4200, "NVIDIA GeForce4 Ti 4200", 9, 6, 4, 3 },
4012 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, "NVIDIA GeForce FX 5200", 7, 15, 11, 7341 },
4013 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, "NVIDIA GeForce FX 5600", 7, 15, 11, 7341 },
4014 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, "NVIDIA GeForce FX 5800", 7, 15, 11, 7341 },
4015 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, "NVIDIA GeForce 6200", 7, 15, 11, 8044 },
4016 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, "NVIDIA GeForce 6600 GT", 7, 15, 11, 8044 },
4017 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, "NVIDIA GeForce 6800", 7, 15, 11, 8044 },
4018 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, "NVIDIA GeForce Go 7300", 7, 15, 11, 8044 },
4019 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, "NVIDIA GeForce Go 7400", 7, 15, 11, 8044 },
4020 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, "NVIDIA GeForce 7600 GT", 7, 15, 11, 8044 },
4021 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, "NVIDIA GeForce 7800 GT", 7, 15, 11, 8044 },
4022 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, "NVIDIA GeForce 8300 GS", 7, 15, 11, 8044 },
4023 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, "NVIDIA GeForce 8600 GT", 7, 15, 11, 8044 },
4024 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, "NVIDIA GeForce 8600M GT", 7, 15, 11, 8044 },
4025 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, "NVIDIA GeForce 8800 GTS", 7, 15, 11, 8044 },
4026 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9200, "NVIDIA GeForce 9200", 7, 15, 11, 8044 },
4027 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400GT, "NVIDIA GeForce 9400 GT", 7, 15, 11, 8044 },
4028 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9500GT, "NVIDIA GeForce 9500 GT", 7, 15, 11, 8044 },
4029 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9600GT, "NVIDIA GeForce 9600 GT", 7, 15, 11, 8044 },
4030 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9800GT, "NVIDIA GeForce 9800 GT", 7, 15, 11, 8044 },
4031 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX260, "NVIDIA GeForce GTX 260", 7, 15, 11, 8044 },
4032 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX275, "NVIDIA GeForce GTX 275", 7, 15, 11, 8044 },
4033 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX280, "NVIDIA GeForce GTX 280", 7, 15, 11, 8044 },
4035 /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode */
4036 {VENDOR_ATI, CARD_ATI_RADEON_9500, "ATI Radeon 9500", 6, 14, 10, 6764 },
4037 {VENDOR_ATI, CARD_ATI_RADEON_X700, "ATI Radeon X700 SE", 6, 14, 10, 6764 },
4038 {VENDOR_ATI, CARD_ATI_RADEON_X1600, "ATI Radeon X1600 Series", 6, 14, 10, 6764 },
4039 {VENDOR_ATI, CARD_ATI_RADEON_HD2300, "ATI Mobility Radeon HD 2300", 6, 14, 10, 6764 },
4040 {VENDOR_ATI, CARD_ATI_RADEON_HD2600, "ATI Mobility Radeon HD 2600", 6, 14, 10, 6764 },
4041 {VENDOR_ATI, CARD_ATI_RADEON_HD2900, "ATI Radeon HD 2900 XT", 6, 14, 10, 6764 },
4042 {VENDOR_ATI, CARD_ATI_RADEON_HD4350, "ATI Radeon HD 4350", 6, 14, 10, 6764 },
4043 {VENDOR_ATI, CARD_ATI_RADEON_HD4600, "ATI Radeon HD 4600 Series", 6, 14, 10, 6764 },
4044 {VENDOR_ATI, CARD_ATI_RADEON_HD4700, "ATI Radeon HD 4700 Series", 6, 14, 10, 6764 },
4045 {VENDOR_ATI, CARD_ATI_RADEON_HD4800, "ATI Radeon HD 4800 Series", 6, 14, 10, 6764 },
4047 /* TODO: Add information about legacy ATI hardware, Intel and other cards */
4050 static BOOL match_ati_r300_to_500(const WineD3D_GL_Info *gl_info) {
4051 if(gl_info->gl_vendor != VENDOR_ATI) return FALSE;
4052 if(gl_info->gl_card == CARD_ATI_RADEON_9500) return TRUE;
4053 if(gl_info->gl_card == CARD_ATI_RADEON_X700) return TRUE;
4054 if(gl_info->gl_card == CARD_ATI_RADEON_X1600) return TRUE;
4055 return FALSE;
4058 static BOOL match_geforce5(const WineD3D_GL_Info *gl_info) {
4059 if(gl_info->gl_vendor == VENDOR_NVIDIA) {
4060 if(gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5800 || gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5600) {
4061 return TRUE;
4064 return FALSE;
4067 static BOOL match_apple_intel(const WineD3D_GL_Info *gl_info) {
4068 return gl_info->gl_vendor == VENDOR_INTEL && match_apple(gl_info);
4071 static BOOL match_apple_nonr500ati(const WineD3D_GL_Info *gl_info) {
4072 if(!match_apple(gl_info)) return FALSE;
4073 if(gl_info->gl_vendor != VENDOR_ATI) return FALSE;
4074 if(gl_info->gl_card == CARD_ATI_RADEON_X1600) return FALSE;
4075 return TRUE;
4078 static BOOL match_fglrx(const WineD3D_GL_Info *gl_info) {
4079 if(gl_info->gl_vendor != VENDOR_ATI) return FALSE;
4080 if(match_apple(gl_info)) return FALSE;
4081 if(strstr(gl_info->gl_renderer, "DRI")) return FALSE; /* Filter out Mesa DRI drivers */
4082 return TRUE;
4085 static BOOL match_dx10_capable(const WineD3D_GL_Info *gl_info) {
4086 /* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
4087 * 44 varyings. So assume that if we have more than 44 varyings we have a dx10 card.
4088 * This detection is for the gl_ClipPos varying quirk. If a d3d9 card really supports more than 44
4089 * varyings and we subtract one in dx9 shaders its not going to hurt us because the dx9 limit is
4090 * hardcoded
4092 * dx10 cards usually have 64 varyings
4094 return gl_info->max_glsl_varyings > 44;
4097 static void quirk_arb_constants(WineD3D_GL_Info *gl_info) {
4098 TRACE_(d3d_caps)("Using ARB vs constant limit(=%u) for GLSL\n", gl_info->vs_arb_constantsF);
4099 gl_info->vs_glsl_constantsF = gl_info->vs_arb_constantsF;
4100 TRACE_(d3d_caps)("Using ARB ps constant limit(=%u) for GLSL\n", gl_info->ps_arb_constantsF);
4101 gl_info->ps_glsl_constantsF = gl_info->ps_arb_constantsF;
4104 static void quirk_apple_glsl_constants(WineD3D_GL_Info *gl_info) {
4105 quirk_arb_constants(gl_info);
4106 /* MacOS needs uniforms for relative addressing offsets. This can accumulate to quite a few uniforms.
4107 * Beyond that the general uniform isn't optimal, so reserve a number of uniforms. 12 vec4's should
4108 * allow 48 different offsets or other helper immediate values
4110 TRACE_(d3d_caps)("Reserving 12 GLSL constants for compiler private use\n");
4111 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
4114 /* fglrx crashes with a very bad kernel panic if GL_POINT_SPRITE_ARB is set to GL_COORD_REPLACE_ARB
4115 * on more than one texture unit. This means that the d3d9 visual point size test will cause a
4116 * kernel panic on any machine running fglrx 9.3(latest that supports r300 to r500 cards). This
4117 * quirk only enables point sprites on the first texture unit. This keeps point sprites working in
4118 * most games, but avoids the crash
4120 * A more sophisticated way would be to find all units that need texture coordinates and enable
4121 * point sprites for one if only one is found, and software emulate point sprites in drawStridedSlow
4122 * if more than one unit needs texture coordinates(This requires software ffp and vertex shaders though)
4124 * Note that disabling the extension entirely does not gain predictability because there is no point
4125 * sprite capability flag in d3d, so the potential rendering bugs are the same if we disable the extension.
4127 static void quirk_one_point_sprite(WineD3D_GL_Info *gl_info) {
4128 if(gl_info->supported[ARB_POINT_SPRITE]) {
4129 TRACE("Limiting point sprites to one texture unit\n");
4130 gl_info->max_point_sprite_units = 1;
4134 static void quirk_ati_dx9(WineD3D_GL_Info *gl_info) {
4135 quirk_arb_constants(gl_info);
4137 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
4138 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
4139 * If real NP2 textures are used, the driver falls back to software. We could just remove the
4140 * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconventient
4141 * due to the non-normalized texture coordinates. Thus set an internal extension flag,
4142 * GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures
4143 * as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits.
4145 * fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it advertises opengl 2.0 which
4146 * has this extension promoted to core. The extension loading code sets this extension supported
4147 * due to that, so this code works on fglrx as well.
4149 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing\n");
4150 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
4151 gl_info->supported[WINE_NORMALIZED_TEXRECT] = TRUE;
4153 /* fglrx has the same structural issues as the one described in quirk_apple_glsl_constants, although
4154 * it is generally more efficient. Reserve just 8 constants
4156 TRACE_(d3d_caps)("Reserving 8 GLSL constants for compiler private use\n");
4157 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 8);
4160 static void quirk_no_np2(WineD3D_GL_Info *gl_info) {
4161 /* The nVidia GeForceFX series reports OpenGL 2.0 capabilities with the latest drivers versions, but
4162 * doesn't explicitly advertise the ARB_tex_npot extension in the GL extension string.
4163 * This usually means that ARB_tex_npot is supported in hardware as long as the application is staying
4164 * within the limits enforced by the ARB_texture_rectangle extension. This however is not true for the
4165 * FX series, which instantly falls back to a slower software path as soon as ARB_tex_npot is used.
4166 * We therefore completely remove ARB_tex_npot from the list of supported extensions.
4168 * Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot,
4169 * triggering the software fallback. There is not much we can do here apart from disabling the
4170 * software-emulated extension and reenable ARB_tex_rect (which was previously disabled
4171 * in IWineD3DImpl_FillGLCaps).
4172 * This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer
4173 * post-processing effects in the game "Max Payne 2").
4174 * The behaviour can be verified through a simple test app attached in bugreport #14724.
4176 TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing\n");
4177 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
4178 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
4181 static void quirk_texcoord_w(WineD3D_GL_Info *gl_info) {
4182 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
4183 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
4184 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
4185 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
4186 * according to the spec.
4188 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
4189 * makes the shader slower and eats instruction slots which should be available to the d3d app.
4191 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
4192 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
4193 * this workaround is activated on cards that do not need it, it won't break things, just affect
4194 * performance negatively.
4196 TRACE("Enabling vertex texture coord fixes in vertex shaders\n");
4197 gl_info->set_texcoord_w = TRUE;
4200 static void quirk_clip_varying(WineD3D_GL_Info *gl_info) {
4201 gl_info->glsl_clip_varying = TRUE;
4204 struct driver_quirk quirk_table[] = {
4206 match_ati_r300_to_500,
4207 quirk_ati_dx9,
4208 "ATI GLSL constant and normalized texrect quirk"
4210 /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
4211 * used it falls back to software. While the compiler can detect if the shader uses all declared
4212 * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
4213 * using relative addressing falls back to software.
4215 * ARB vp gives the correct amount of uniforms, so use it instead of GLSL
4218 match_apple,
4219 quirk_apple_glsl_constants,
4220 "Apple GLSL uniform override"
4223 match_geforce5,
4224 quirk_no_np2,
4225 "Geforce 5 NP2 disable"
4228 match_apple_intel,
4229 quirk_texcoord_w,
4230 "Init texcoord .w for Apple Intel GPU driver"
4233 match_apple_nonr500ati,
4234 quirk_texcoord_w,
4235 "Init texcoord .w for Apple ATI >= r600 GPU driver"
4238 match_fglrx,
4239 quirk_one_point_sprite,
4240 "Fglrx point sprite crash workaround"
4243 match_dx10_capable,
4244 quirk_clip_varying,
4245 "Reserved varying for gl_ClipPos"
4249 static void fixup_extensions(WineD3D_GL_Info *gl_info) {
4250 unsigned int i;
4252 for(i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); i++) {
4253 if(!quirk_table[i].match(gl_info)) continue;
4254 TRACE_(d3d_caps)("Applying driver quirk \"%s\"\n", quirk_table[i].description);
4255 quirk_table[i].apply(gl_info);
4258 /* Find out if PBOs work as they are supposed to */
4259 test_pbo_functionality(gl_info);
4261 /* Fixup the driver version */
4262 for(i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++) {
4263 if(gl_info->gl_vendor == driver_version_table[i].vendor &&
4264 gl_info->gl_card == driver_version_table[i].card) {
4265 TRACE_(d3d_caps)("Found card 0x%04x, 0x%04x in driver version DB\n", gl_info->gl_vendor, gl_info->gl_card);
4267 gl_info->driver_version = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
4268 driver_version_table[i].lopart_lo);
4269 gl_info->driver_version_hipart = MAKEDWORD_VERSION(driver_version_table[i].hipart_hi,
4270 driver_version_table[i].hipart_lo);
4271 strcpy(gl_info->driver_description, driver_version_table[i].description);
4272 break;
4277 static void WINE_GLAPI invalid_func(const void *data)
4279 ERR("Invalid vertex attribute function called\n");
4280 DebugBreak();
4283 static void WINE_GLAPI invalid_texcoord_func(GLenum unit, const void *data)
4285 ERR("Invalid texcoord function called\n");
4286 DebugBreak();
4289 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
4290 * the extension detection and are used in drawStridedSlow
4292 static void WINE_GLAPI position_d3dcolor(const void *data)
4294 DWORD pos = *((const DWORD *)data);
4296 FIXME("Add a test for fixed function position from d3dcolor type\n");
4297 glVertex4s(D3DCOLOR_B_R(pos),
4298 D3DCOLOR_B_G(pos),
4299 D3DCOLOR_B_B(pos),
4300 D3DCOLOR_B_A(pos));
4303 static void WINE_GLAPI position_float4(const void *data)
4305 const GLfloat *pos = data;
4307 if (pos[3] != 0.0 && pos[3] != 1.0)
4309 float w = 1.0 / pos[3];
4311 glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
4313 else
4315 glVertex3fv(pos);
4319 static void WINE_GLAPI diffuse_d3dcolor(const void *data)
4321 DWORD diffuseColor = *((const DWORD *)data);
4323 glColor4ub(D3DCOLOR_B_R(diffuseColor),
4324 D3DCOLOR_B_G(diffuseColor),
4325 D3DCOLOR_B_B(diffuseColor),
4326 D3DCOLOR_B_A(diffuseColor));
4329 static void WINE_GLAPI specular_d3dcolor(const void *data)
4331 DWORD specularColor = *((const DWORD *)data);
4332 GLbyte d[] = {D3DCOLOR_B_R(specularColor),
4333 D3DCOLOR_B_G(specularColor),
4334 D3DCOLOR_B_B(specularColor)};
4336 specular_func_3ubv(d);
4339 static void WINE_GLAPI warn_no_specular_func(const void *data)
4341 WARN("GL_EXT_secondary_color not supported\n");
4344 static void fillGLAttribFuncs(const WineD3D_GL_Info *gl_info)
4346 position_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4347 position_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4348 position_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)glVertex3fv;
4349 position_funcs[WINED3D_FFP_EMIT_FLOAT4] = position_float4;
4350 position_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = position_d3dcolor;
4351 position_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4352 position_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4353 position_funcs[WINED3D_FFP_EMIT_SHORT4] = (glAttribFunc)glVertex2sv;
4354 position_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4355 position_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4356 position_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4357 position_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4358 position_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4359 position_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4360 position_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4361 position_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4362 position_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4364 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4365 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4366 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)glColor3fv;
4367 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glAttribFunc)glColor4fv;
4368 diffuse_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = diffuse_d3dcolor;
4369 diffuse_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4370 diffuse_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4371 diffuse_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4372 diffuse_funcs[WINED3D_FFP_EMIT_UBYTE4N] = (glAttribFunc)glColor4ubv;
4373 diffuse_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4374 diffuse_funcs[WINED3D_FFP_EMIT_SHORT4N] = (glAttribFunc)glColor4sv;
4375 diffuse_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4376 diffuse_funcs[WINED3D_FFP_EMIT_USHORT4N] = (glAttribFunc)glColor4usv;
4377 diffuse_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4378 diffuse_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4379 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4380 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4382 /* No 4 component entry points here */
4383 specular_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4384 specular_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4385 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
4386 specular_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)GL_EXTCALL(glSecondaryColor3fvEXT);
4387 } else {
4388 specular_funcs[WINED3D_FFP_EMIT_FLOAT3] = warn_no_specular_func;
4390 specular_funcs[WINED3D_FFP_EMIT_FLOAT4] = invalid_func;
4391 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
4392 specular_func_3ubv = (glAttribFunc)GL_EXTCALL(glSecondaryColor3ubvEXT);
4393 specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = specular_d3dcolor;
4394 } else {
4395 specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = warn_no_specular_func;
4397 specular_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4398 specular_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4399 specular_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4400 specular_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4401 specular_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4402 specular_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4403 specular_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4404 specular_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4405 specular_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4406 specular_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4407 specular_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4408 specular_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4410 /* Only 3 component entry points here. Test how others behave. Float4 normals are used
4411 * by one of our tests, trying to pass it to the pixel shader, which fails on Windows.
4413 normal_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4414 normal_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4415 normal_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)glNormal3fv;
4416 normal_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glAttribFunc)glNormal3fv; /* Just ignore the 4th value */
4417 normal_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_func;
4418 normal_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4419 normal_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4420 normal_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4421 normal_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4422 normal_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4423 normal_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4424 normal_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4425 normal_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4426 normal_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4427 normal_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4428 normal_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4429 normal_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4431 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT1] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord1fvARB);
4432 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2fvARB);
4433 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord3fvARB);
4434 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4fvARB);
4435 multi_texcoord_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_texcoord_func;
4436 multi_texcoord_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_texcoord_func;
4437 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2svARB);
4438 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4svARB);
4439 multi_texcoord_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_texcoord_func;
4440 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_texcoord_func;
4441 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_texcoord_func;
4442 multi_texcoord_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_texcoord_func;
4443 multi_texcoord_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_texcoord_func;
4444 multi_texcoord_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_texcoord_func;
4445 multi_texcoord_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_texcoord_func;
4446 if (GL_SUPPORT(NV_HALF_FLOAT))
4448 /* Not supported by ARB_HALF_FLOAT_VERTEX, so check for NV_HALF_FLOAT */
4449 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2hvNV);
4450 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4hvNV);
4451 } else {
4452 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_texcoord_func;
4453 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_texcoord_func;
4457 BOOL InitAdapters(IWineD3DImpl *This)
4459 static HMODULE mod_gl;
4460 BOOL ret;
4461 int ps_selected_mode, vs_selected_mode;
4463 /* No need to hold any lock. The calling library makes sure only one thread calls
4464 * wined3d simultaneously
4467 TRACE("Initializing adapters\n");
4469 if(!mod_gl) {
4470 #ifdef USE_WIN32_OPENGL
4471 #define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
4472 mod_gl = LoadLibraryA("opengl32.dll");
4473 if(!mod_gl) {
4474 ERR("Can't load opengl32.dll!\n");
4475 goto nogl_adapter;
4477 #else
4478 #define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
4479 /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
4480 mod_gl = GetModuleHandleA("gdi32.dll");
4481 #endif
4484 /* Load WGL core functions from opengl32.dll */
4485 #define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn);
4486 WGL_FUNCS_GEN;
4487 #undef USE_WGL_FUNC
4489 if(!pwglGetProcAddress) {
4490 ERR("Unable to load wglGetProcAddress!\n");
4491 goto nogl_adapter;
4494 /* Dynamically load all GL core functions */
4495 GL_FUNCS_GEN;
4496 #undef USE_GL_FUNC
4498 /* Load glFinish and glFlush from opengl32.dll even if we're not using WIN32 opengl
4499 * otherwise because we have to use winex11.drv's override
4501 #ifdef USE_WIN32_OPENGL
4502 glFinish = (void*)GetProcAddress(mod_gl, "glFinish");
4503 glFlush = (void*)GetProcAddress(mod_gl, "glFlush");
4504 #else
4505 glFinish = (void*)pwglGetProcAddress("wglFinish");
4506 glFlush = (void*)pwglGetProcAddress("wglFlush");
4507 #endif
4509 glEnableWINE = glEnable;
4510 glDisableWINE = glDisable;
4512 /* For now only one default adapter */
4514 struct WineD3DAdapter *adapter = &This->adapters[0];
4515 const WineD3D_GL_Info *gl_info = &adapter->gl_info;
4516 int iPixelFormat;
4517 int res;
4518 int i;
4519 WineD3D_PixelFormat *cfgs;
4520 DISPLAY_DEVICEW DisplayDevice;
4521 HDC hdc;
4523 TRACE("Initializing default adapter\n");
4524 adapter->num = 0;
4525 adapter->monitorPoint.x = -1;
4526 adapter->monitorPoint.y = -1;
4528 if (!WineD3D_CreateFakeGLContext()) {
4529 ERR("Failed to get a gl context for default adapter\n");
4530 WineD3D_ReleaseFakeGLContext();
4531 goto nogl_adapter;
4534 ret = IWineD3DImpl_FillGLCaps(&adapter->gl_info);
4535 if(!ret) {
4536 ERR("Failed to initialize gl caps for default adapter\n");
4537 WineD3D_ReleaseFakeGLContext();
4538 goto nogl_adapter;
4540 ret = initPixelFormats(&adapter->gl_info);
4541 if(!ret) {
4542 ERR("Failed to init gl formats\n");
4543 WineD3D_ReleaseFakeGLContext();
4544 goto nogl_adapter;
4547 hdc = pwglGetCurrentDC();
4548 if(!hdc) {
4549 ERR("Failed to get gl HDC\n");
4550 WineD3D_ReleaseFakeGLContext();
4551 goto nogl_adapter;
4554 adapter->driver = "Display";
4555 adapter->description = "Direct3D HAL";
4557 /* Use the VideoRamSize registry setting when set */
4558 if(wined3d_settings.emulated_textureram)
4559 adapter->TextureRam = wined3d_settings.emulated_textureram;
4560 else
4561 adapter->TextureRam = adapter->gl_info.vidmem;
4562 adapter->UsedTextureRam = 0;
4563 TRACE("Emulating %dMB of texture ram\n", adapter->TextureRam/(1024*1024));
4565 /* Initialize the Adapter's DeviceName which is required for ChangeDisplaySettings and friends */
4566 DisplayDevice.cb = sizeof(DisplayDevice);
4567 EnumDisplayDevicesW(NULL, 0 /* Adapter 0 = iDevNum 0 */, &DisplayDevice, 0);
4568 TRACE("DeviceName: %s\n", debugstr_w(DisplayDevice.DeviceName));
4569 strcpyW(adapter->DeviceName, DisplayDevice.DeviceName);
4571 if(GL_SUPPORT(WGL_ARB_PIXEL_FORMAT))
4573 int attribute;
4574 int attribs[10];
4575 int values[10];
4576 int nAttribs = 0;
4578 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
4579 GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, &attribute, &adapter->nCfgs));
4581 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, adapter->nCfgs *sizeof(WineD3D_PixelFormat));
4582 cfgs = adapter->cfgs;
4583 attribs[nAttribs++] = WGL_RED_BITS_ARB;
4584 attribs[nAttribs++] = WGL_GREEN_BITS_ARB;
4585 attribs[nAttribs++] = WGL_BLUE_BITS_ARB;
4586 attribs[nAttribs++] = WGL_ALPHA_BITS_ARB;
4587 attribs[nAttribs++] = WGL_DEPTH_BITS_ARB;
4588 attribs[nAttribs++] = WGL_STENCIL_BITS_ARB;
4589 attribs[nAttribs++] = WGL_DRAW_TO_WINDOW_ARB;
4590 attribs[nAttribs++] = WGL_PIXEL_TYPE_ARB;
4591 attribs[nAttribs++] = WGL_DOUBLE_BUFFER_ARB;
4592 attribs[nAttribs++] = WGL_AUX_BUFFERS_ARB;
4594 for (iPixelFormat=1; iPixelFormat <= adapter->nCfgs; ++iPixelFormat)
4596 res = GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, nAttribs, attribs, values));
4598 if(!res)
4599 continue;
4601 /* Cache the pixel format */
4602 cfgs->iPixelFormat = iPixelFormat;
4603 cfgs->redSize = values[0];
4604 cfgs->greenSize = values[1];
4605 cfgs->blueSize = values[2];
4606 cfgs->alphaSize = values[3];
4607 cfgs->depthSize = values[4];
4608 cfgs->stencilSize = values[5];
4609 cfgs->windowDrawable = values[6];
4610 cfgs->iPixelType = values[7];
4611 cfgs->doubleBuffer = values[8];
4612 cfgs->auxBuffers = values[9];
4614 cfgs->pbufferDrawable = FALSE;
4615 /* Check for pbuffer support when it is around as wglGetPixelFormatAttribiv fails for unknown attributes. */
4616 if(GL_SUPPORT(WGL_ARB_PBUFFER)) {
4617 int attrib = WGL_DRAW_TO_PBUFFER_ARB;
4618 int value;
4619 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 1, &attrib, &value)))
4620 cfgs->pbufferDrawable = value;
4623 cfgs->numSamples = 0;
4624 /* Check multisample support */
4625 if(GL_SUPPORT(ARB_MULTISAMPLE)) {
4626 int attrib[2] = {WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB};
4627 int value[2];
4628 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 2, attrib, value))) {
4629 /* value[0] = WGL_SAMPLE_BUFFERS_ARB which tells whether multisampling is supported.
4630 * value[1] = number of multi sample buffers*/
4631 if(value[0])
4632 cfgs->numSamples = value[1];
4636 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);
4637 cfgs++;
4640 else
4642 int nCfgs = DescribePixelFormat(hdc, 0, 0, 0);
4643 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nCfgs*sizeof(WineD3D_PixelFormat));
4644 adapter->nCfgs = 0; /* We won't accept all formats e.g. software accelerated ones will be skipped */
4646 cfgs = adapter->cfgs;
4647 for(iPixelFormat=1; iPixelFormat<=nCfgs; iPixelFormat++)
4649 PIXELFORMATDESCRIPTOR ppfd;
4651 res = DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &ppfd);
4652 if(!res)
4653 continue;
4655 /* We only want HW acceleration using an OpenGL ICD driver.
4656 * PFD_GENERIC_FORMAT = slow opengl 1.1 gdi software rendering
4657 * PFD_GENERIC_ACCELERATED = partial hw acceleration using a MCD driver (e.g. 3dfx minigl)
4659 if(ppfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED))
4661 TRACE("Skipping iPixelFormat=%d because it isn't ICD accelerated\n", iPixelFormat);
4662 continue;
4665 cfgs->iPixelFormat = iPixelFormat;
4666 cfgs->redSize = ppfd.cRedBits;
4667 cfgs->greenSize = ppfd.cGreenBits;
4668 cfgs->blueSize = ppfd.cBlueBits;
4669 cfgs->alphaSize = ppfd.cAlphaBits;
4670 cfgs->depthSize = ppfd.cDepthBits;
4671 cfgs->stencilSize = ppfd.cStencilBits;
4672 cfgs->pbufferDrawable = 0;
4673 cfgs->windowDrawable = (ppfd.dwFlags & PFD_DRAW_TO_WINDOW) ? 1 : 0;
4674 cfgs->iPixelType = (ppfd.iPixelType == PFD_TYPE_RGBA) ? WGL_TYPE_RGBA_ARB : WGL_TYPE_COLORINDEX_ARB;
4675 cfgs->doubleBuffer = (ppfd.dwFlags & PFD_DOUBLEBUFFER) ? 1 : 0;
4676 cfgs->auxBuffers = ppfd.cAuxBuffers;
4677 cfgs->numSamples = 0;
4679 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);
4680 cfgs++;
4681 adapter->nCfgs++;
4684 /* 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 */
4685 if(!adapter->nCfgs)
4687 ERR("Disabling Direct3D because no hardware accelerated pixel formats have been found!\n");
4689 WineD3D_ReleaseFakeGLContext();
4690 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
4691 goto nogl_adapter;
4695 /* D16, D24X8 and D24S8 are common depth / depth+stencil formats. All drivers support them though this doesn't
4696 * mean that the format is offered in hardware. For instance Geforce8 cards don't have offer D16 in hardware
4697 * but just fake it using D24(X8?) which is fine. D3D also allows that.
4698 * Some display drivers (i915 on Linux) only report mixed depth+stencil formats like D24S8. MSDN clearly mentions
4699 * that only on lockable formats (e.g. D16_locked) the bit order is guaranteed and that on other formats the
4700 * driver is allowed to consume more bits EXCEPT for stencil bits.
4702 * Mark an adapter with this broken stencil behavior.
4704 adapter->brokenStencil = TRUE;
4705 for (i = 0, cfgs = adapter->cfgs; i < adapter->nCfgs; ++i)
4707 /* Nearly all drivers offer depth formats without stencil, only on i915 this if-statement won't be entered. */
4708 if(cfgs[i].depthSize && !cfgs[i].stencilSize) {
4709 adapter->brokenStencil = FALSE;
4710 break;
4714 fixup_extensions(&adapter->gl_info);
4715 add_gl_compat_wrappers(&adapter->gl_info);
4717 WineD3D_ReleaseFakeGLContext();
4719 select_shader_mode(&adapter->gl_info, WINED3DDEVTYPE_HAL, &ps_selected_mode, &vs_selected_mode);
4720 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &adapter->gl_info);
4721 fillGLAttribFuncs(&adapter->gl_info);
4722 adapter->opengl = TRUE;
4724 This->adapter_count = 1;
4725 TRACE("%u adapters successfully initialized\n", This->adapter_count);
4727 return TRUE;
4729 nogl_adapter:
4730 /* Initialize an adapter for ddraw-only memory counting */
4731 memset(This->adapters, 0, sizeof(This->adapters));
4732 This->adapters[0].num = 0;
4733 This->adapters[0].opengl = FALSE;
4734 This->adapters[0].monitorPoint.x = -1;
4735 This->adapters[0].monitorPoint.y = -1;
4737 This->adapters[0].driver = "Display";
4738 This->adapters[0].description = "WineD3D DirectDraw Emulation";
4739 if(wined3d_settings.emulated_textureram) {
4740 This->adapters[0].TextureRam = wined3d_settings.emulated_textureram;
4741 } else {
4742 This->adapters[0].TextureRam = 8 * 1024 * 1024; /* This is plenty for a DDraw-only card */
4745 initPixelFormatsNoGL(&This->adapters[0].gl_info);
4747 This->adapter_count = 1;
4748 return FALSE;
4751 /**********************************************************
4752 * IWineD3D VTbl follows
4753 **********************************************************/
4755 const IWineD3DVtbl IWineD3D_Vtbl =
4757 /* IUnknown */
4758 IWineD3DImpl_QueryInterface,
4759 IWineD3DImpl_AddRef,
4760 IWineD3DImpl_Release,
4761 /* IWineD3D */
4762 IWineD3DImpl_GetParent,
4763 IWineD3DImpl_GetAdapterCount,
4764 IWineD3DImpl_RegisterSoftwareDevice,
4765 IWineD3DImpl_GetAdapterMonitor,
4766 IWineD3DImpl_GetAdapterModeCount,
4767 IWineD3DImpl_EnumAdapterModes,
4768 IWineD3DImpl_GetAdapterDisplayMode,
4769 IWineD3DImpl_GetAdapterIdentifier,
4770 IWineD3DImpl_CheckDeviceMultiSampleType,
4771 IWineD3DImpl_CheckDepthStencilMatch,
4772 IWineD3DImpl_CheckDeviceType,
4773 IWineD3DImpl_CheckDeviceFormat,
4774 IWineD3DImpl_CheckDeviceFormatConversion,
4775 IWineD3DImpl_GetDeviceCaps,
4776 IWineD3DImpl_CreateDevice