wined3d: Update nvidia GPUs.
[wine/wine-kai.git] / dlls / wined3d / directx.c
blob7df23d475ef784a51e6c7bbb5344b9422301cf1c
1 /*
2 * IWineD3D implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 /* Compile time diagnostics: */
27 #ifndef DEBUG_SINGLE_MODE
28 /* Set to 1 to force only a single display mode to be exposed: */
29 #define DEBUG_SINGLE_MODE 0
30 #endif
33 #include "config.h"
34 #include <assert.h>
35 #include "wined3d_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
38 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
40 /* The d3d device ID */
41 static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
43 /* Extension detection */
44 static const struct {
45 const char *extension_string;
46 GL_SupportedExt extension;
47 DWORD version;
48 } EXTENSION_MAP[] = {
49 /* APPLE */
50 {"GL_APPLE_client_storage", APPLE_CLIENT_STORAGE, 0 },
51 {"GL_APPLE_fence", APPLE_FENCE, 0 },
52 {"GL_APPLE_flush_render", APPLE_FLUSH_RENDER, 0 },
53 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422, 0 },
54 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS, 0 },
56 /* ATI */
57 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL, 0 },
58 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3, 0 },
59 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE, 0 },
60 {"GL_ATI_envmap_bumpmap", ATI_ENVMAP_BUMPMAP, 0 },
61 {"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER, 0 },
63 /* ARB */
64 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS, 0 },
65 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM, 0 },
66 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER, 0 },
67 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL, 0 },
68 {"GL_ARB_imaging", ARB_IMAGING, 0 },
69 {"GL_ARB_multisample", ARB_MULTISAMPLE, 0 }, /* needs GLX_ARB_MULTISAMPLE as well */
70 {"GL_ARB_multitexture", ARB_MULTITEXTURE, 0 },
71 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY, 0 },
72 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT, 0 },
73 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS, 0 },
74 {"GL_ARB_point_sprite", ARB_POINT_SPRITE, 0 },
75 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP, 0 },
76 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION, 0 },
77 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP, 0 },
78 {"GL_ARB_texture_env_add", ARB_TEXTURE_ENV_ADD, 0 },
79 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE, 0 },
80 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3, 0 },
81 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT, 0 },
82 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT, 0 },
83 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO, 0 },
84 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE, 0 },
85 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND, 0 },
86 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT, 0 },
87 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM, 0 },
88 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER, 0 },
89 {"GL_ARB_shader_objects", ARB_SHADER_OBJECTS, 0 },
91 /* EXT */
92 {"GL_EXT_blend_color", EXT_BLEND_COLOR, 0 },
93 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX, 0 },
94 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE, 0 },
95 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE, 0 },
96 {"GL_EXT_fog_coord", EXT_FOG_COORD, 0 },
97 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT, 0 },
98 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT, 0 },
99 {"GL_EXT_paletted_texture", EXT_PALETTED_TEXTURE, 0 },
100 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS, 0 },
101 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR, 0 },
102 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE, 0 },
103 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP, 0 },
104 {"GL_EXT_texture3D", EXT_TEXTURE3D, MAKEDWORD_VERSION(1, 2) },
105 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC, 0 },
106 {"GL_EXT_texture_env_add", EXT_TEXTURE_ENV_ADD, 0 },
107 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE, 0 },
108 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3, 0 },
109 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB, 0 },
110 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC, 0 },
111 {"GL_EXT_texture_lod", EXT_TEXTURE_LOD, 0 },
112 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS, 0 },
113 {"GL_EXT_vertex_shader", EXT_VERTEX_SHADER, 0 },
114 {"GL_EXT_vertex_weighting", EXT_VERTEX_WEIGHTING, 0 },
115 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS, 0 },
117 /* NV */
118 {"GL_NV_half_float", NV_HALF_FLOAT, 0 },
119 {"GL_NV_fence", NV_FENCE, 0 },
120 {"GL_NV_fog_distance", NV_FOG_DISTANCE, 0 },
121 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM, 0 },
122 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2, 0 },
123 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS, 0 },
124 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2, 0 },
125 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION, 0 },
126 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4, 0 },
127 {"GL_NV_texture_shader", NV_TEXTURE_SHADER, 0 },
128 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2, 0 },
129 {"GL_NV_texture_shader3", NV_TEXTURE_SHADER3, 0 },
130 {"GL_NV_occlusion_query", NV_OCCLUSION_QUERY, 0 },
131 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM, 0 },
132 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1, 0 },
133 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2, 0 },
134 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3, 0 },
135 {"GL_NV_depth_clamp", NV_DEPTH_CLAMP, 0 },
136 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT, 0 },
138 /* SGI */
139 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP, 0 },
142 /**********************************************************
143 * Utility functions follow
144 **********************************************************/
146 /* Adapters */
147 static int numAdapters = 0;
148 static struct WineD3DAdapter Adapters[1];
150 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat);
152 /* lookup tables */
153 int minLookup[MAX_LOOKUPS];
154 int maxLookup[MAX_LOOKUPS];
155 DWORD *stateLookup[MAX_LOOKUPS];
157 DWORD minMipLookup[WINED3DTEXF_ANISOTROPIC + 1][WINED3DTEXF_LINEAR + 1];
158 DWORD minMipLookup_noFilter[WINED3DTEXF_ANISOTROPIC + 1][WINED3DTEXF_LINEAR + 1] = {
159 {GL_NEAREST, GL_NEAREST, GL_NEAREST},
160 {GL_NEAREST, GL_NEAREST, GL_NEAREST},
161 {GL_NEAREST, GL_NEAREST, GL_NEAREST},
162 {GL_NEAREST, GL_NEAREST, GL_NEAREST},
165 DWORD magLookup[WINED3DTEXF_ANISOTROPIC + 1];
166 DWORD magLookup_noFilter[WINED3DTEXF_ANISOTROPIC + 1] = {
167 GL_NEAREST, GL_NEAREST, GL_NEAREST, GL_NEAREST
170 /* drawStridedSlow attributes */
171 glAttribFunc position_funcs[WINED3DDECLTYPE_UNUSED];
172 glAttribFunc diffuse_funcs[WINED3DDECLTYPE_UNUSED];
173 glAttribFunc specular_funcs[WINED3DDECLTYPE_UNUSED];
174 glAttribFunc normal_funcs[WINED3DDECLTYPE_UNUSED];
175 glTexAttribFunc texcoord_funcs[WINED3DDECLTYPE_UNUSED];
178 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created,
179 * i.e., there is no GL Context - Get a default rendering context to enable the
180 * function query some info from GL.
183 static int wined3d_fake_gl_context_ref = 0;
184 static BOOL wined3d_fake_gl_context_foreign;
185 static BOOL wined3d_fake_gl_context_available = FALSE;
186 static HDC wined3d_fake_gl_context_hdc = NULL;
187 static HWND wined3d_fake_gl_context_hwnd = NULL;
189 static CRITICAL_SECTION wined3d_fake_gl_context_cs;
190 static CRITICAL_SECTION_DEBUG wined3d_fake_gl_context_cs_debug =
192 0, 0, &wined3d_fake_gl_context_cs,
193 { &wined3d_fake_gl_context_cs_debug.ProcessLocksList,
194 &wined3d_fake_gl_context_cs_debug.ProcessLocksList },
195 0, 0, { (DWORD_PTR)(__FILE__ ": wined3d_fake_gl_context_cs") }
197 static CRITICAL_SECTION wined3d_fake_gl_context_cs = { &wined3d_fake_gl_context_cs_debug, -1, 0, 0, 0, 0 };
199 static void WineD3D_ReleaseFakeGLContext(void) {
200 HGLRC glCtx;
202 EnterCriticalSection(&wined3d_fake_gl_context_cs);
204 if(!wined3d_fake_gl_context_available) {
205 TRACE_(d3d_caps)("context not available\n");
206 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
207 return;
210 glCtx = pwglGetCurrentContext();
212 TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref);
213 if (0 == (--wined3d_fake_gl_context_ref) ) {
214 if(!wined3d_fake_gl_context_foreign && glCtx) {
215 TRACE_(d3d_caps)("destroying fake GL context\n");
216 pwglMakeCurrent(NULL, NULL);
217 pwglDeleteContext(glCtx);
219 if(wined3d_fake_gl_context_hdc)
220 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
221 wined3d_fake_gl_context_hdc = NULL; /* Make sure we don't think that it is still around */
222 if(wined3d_fake_gl_context_hwnd)
223 DestroyWindow(wined3d_fake_gl_context_hwnd);
224 wined3d_fake_gl_context_hwnd = NULL;
225 wined3d_fake_gl_context_available = FALSE;
227 assert(wined3d_fake_gl_context_ref >= 0);
229 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
232 static BOOL WineD3D_CreateFakeGLContext(void) {
233 HGLRC glCtx = NULL;
235 EnterCriticalSection(&wined3d_fake_gl_context_cs);
237 TRACE("getting context...\n");
238 if(wined3d_fake_gl_context_ref > 0) goto ret;
239 assert(0 == wined3d_fake_gl_context_ref);
241 wined3d_fake_gl_context_foreign = TRUE;
243 glCtx = pwglGetCurrentContext();
244 if (!glCtx) {
245 PIXELFORMATDESCRIPTOR pfd;
246 int iPixelFormat;
248 wined3d_fake_gl_context_foreign = FALSE;
250 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes */
251 wined3d_fake_gl_context_hwnd = CreateWindowA("WineD3D_OpenGL", "WineD3D fake window", WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
252 if(!wined3d_fake_gl_context_hwnd) {
253 ERR("HWND creation failed!\n");
254 goto fail;
256 wined3d_fake_gl_context_hdc = GetDC(wined3d_fake_gl_context_hwnd);
257 if(!wined3d_fake_gl_context_hdc) {
258 ERR("GetDC failed!\n");
259 goto fail;
262 /* PixelFormat selection */
263 ZeroMemory(&pfd, sizeof(pfd));
264 pfd.nSize = sizeof(pfd);
265 pfd.nVersion = 1;
266 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;/*PFD_GENERIC_ACCELERATED*/
267 pfd.iPixelType = PFD_TYPE_RGBA;
268 pfd.cColorBits = 32;
269 pfd.iLayerType = PFD_MAIN_PLANE;
271 iPixelFormat = ChoosePixelFormat(wined3d_fake_gl_context_hdc, &pfd);
272 if(!iPixelFormat) {
273 /* If this happens something is very wrong as ChoosePixelFormat barely fails */
274 ERR("Can't find a suitable iPixelFormat\n");
275 goto fail;
277 DescribePixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, sizeof(pfd), &pfd);
278 SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd);
280 /* Create a GL context */
281 glCtx = pwglCreateContext(wined3d_fake_gl_context_hdc);
282 if (!glCtx) {
283 WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
284 goto fail;
287 /* Make it the current GL context */
288 if (!pwglMakeCurrent(wined3d_fake_gl_context_hdc, glCtx)) {
289 WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
290 goto fail;
294 ret:
295 TRACE("incrementing ref from %i\n", wined3d_fake_gl_context_ref);
296 wined3d_fake_gl_context_ref++;
297 wined3d_fake_gl_context_available = TRUE;
298 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
299 return TRUE;
300 fail:
301 if(wined3d_fake_gl_context_hdc)
302 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
303 wined3d_fake_gl_context_hdc = NULL;
304 if(wined3d_fake_gl_context_hwnd)
305 DestroyWindow(wined3d_fake_gl_context_hwnd);
306 wined3d_fake_gl_context_hwnd = NULL;
307 if(glCtx) pwglDeleteContext(glCtx);
308 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
309 return FALSE;
312 /* Adjust the amount of used texture memory */
313 long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram){
314 UINT Adapter = D3DDevice->adapterNo;
316 Adapters[Adapter].UsedTextureRam += glram;
317 TRACE("Adjusted gl ram by %ld to %d\n", glram, Adapters[Adapter].UsedTextureRam);
318 return Adapters[Adapter].UsedTextureRam;
321 /**********************************************************
322 * IUnknown parts follows
323 **********************************************************/
325 static HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
327 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
329 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
330 if (IsEqualGUID(riid, &IID_IUnknown)
331 || IsEqualGUID(riid, &IID_IWineD3DBase)
332 || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
333 IUnknown_AddRef(iface);
334 *ppobj = This;
335 return S_OK;
337 *ppobj = NULL;
338 return E_NOINTERFACE;
341 static ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
342 IWineD3DImpl *This = (IWineD3DImpl *)iface;
343 ULONG refCount = InterlockedIncrement(&This->ref);
345 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
346 return refCount;
349 static ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
350 IWineD3DImpl *This = (IWineD3DImpl *)iface;
351 ULONG ref;
352 TRACE("(%p) : Releasing from %d\n", This, This->ref);
353 ref = InterlockedDecrement(&This->ref);
354 if (ref == 0) {
355 HeapFree(GetProcessHeap(), 0, This);
358 return ref;
361 /* Set the shader type for this device, depending on the given capabilities,
362 * the device type, and the user preferences in wined3d_settings */
364 void select_shader_mode(
365 WineD3D_GL_Info *gl_info,
366 WINED3DDEVTYPE DeviceType,
367 int* ps_selected,
368 int* vs_selected) {
370 if (wined3d_settings.vs_mode == VS_NONE) {
371 *vs_selected = SHADER_NONE;
372 } else if (gl_info->supported[ARB_VERTEX_SHADER] && wined3d_settings.glslRequested) {
373 /* Geforce4 cards support GLSL but for vertex shaders only. Further its reported GLSL caps are
374 * wrong. This combined with the fact that glsl won't offer more features or performance, use ARB
375 * shaders only on this card. */
376 if(gl_info->vs_nv_version && gl_info->vs_nv_version < VS_VERSION_20)
377 *vs_selected = SHADER_ARB;
378 else
379 *vs_selected = SHADER_GLSL;
380 } else if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
381 *vs_selected = SHADER_ARB;
382 } else {
383 *vs_selected = SHADER_NONE;
386 if (wined3d_settings.ps_mode == PS_NONE) {
387 *ps_selected = SHADER_NONE;
388 } else if (gl_info->supported[ARB_FRAGMENT_SHADER] && wined3d_settings.glslRequested) {
389 *ps_selected = SHADER_GLSL;
390 } else if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
391 *ps_selected = SHADER_ARB;
392 } else if (gl_info->supported[ATI_FRAGMENT_SHADER]) {
393 *ps_selected = SHADER_ATI;
394 } else {
395 *ps_selected = SHADER_NONE;
399 /** Select the number of report maximum shader constants based on the selected shader modes */
400 static void select_shader_max_constants(
401 int ps_selected_mode,
402 int vs_selected_mode,
403 WineD3D_GL_Info *gl_info) {
405 switch (vs_selected_mode) {
406 case SHADER_GLSL:
407 /* Subtract the other potential uniforms from the max available (bools, ints, and 1 row of projection matrix) */
408 gl_info->max_vshader_constantsF = gl_info->vs_glsl_constantsF - (MAX_CONST_B / 4) - MAX_CONST_I - 1;
409 break;
410 case SHADER_ARB:
411 /* We have to subtract any other PARAMs that we might use in our shader programs.
412 * ATI seems to count 2 implicit PARAMs when we use fog and NVIDIA counts 1,
413 * and we reference one row of the PROJECTION matrix which counts as 1 PARAM. */
414 gl_info->max_vshader_constantsF = gl_info->vs_arb_constantsF - 3;
415 break;
416 default:
417 gl_info->max_vshader_constantsF = 0;
418 break;
421 switch (ps_selected_mode) {
422 case SHADER_GLSL:
423 /* Subtract the other potential uniforms from the max available (bools & ints), and 2 states for fog.
424 * In theory the texbem instruction may need one more shader constant too. But lets assume
425 * that a sm <= 1.3 shader does not need all the uniforms provided by a glsl-capable card,
426 * and lets not take away a uniform needlessly from all other shaders.
428 gl_info->max_pshader_constantsF = gl_info->ps_glsl_constantsF - (MAX_CONST_B / 4) - MAX_CONST_I - 2;
429 break;
430 case SHADER_ARB:
431 /* The arb shader only loads the bump mapping environment matrix into the shader if it finds
432 * a free constant to do that, so only reduce the number of available constants by 2 for the fog states.
434 gl_info->max_pshader_constantsF = gl_info->ps_arb_constantsF - 2;
435 break;
436 default:
437 gl_info->max_pshader_constantsF = 0;
438 break;
442 /**********************************************************
443 * IWineD3D parts follows
444 **********************************************************/
446 #define GLINFO_LOCATION (*gl_info)
447 static inline BOOL test_arb_vs_offset_limit(WineD3D_GL_Info *gl_info) {
448 GLuint prog;
449 BOOL ret = FALSE;
450 const char *testcode =
451 "!!ARBvp1.0\n"
452 "PARAM C[66] = { program.env[0..65] };\n"
453 "ADDRESS A0;"
454 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
455 "ARL A0.x, zero.x;\n"
456 "MOV result.position, C[A0.x + 65];\n"
457 "END\n";
459 while(glGetError());
460 GL_EXTCALL(glGenProgramsARB(1, &prog));
461 if(!prog) {
462 ERR("Failed to create an ARB offset limit test program\n");
464 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
465 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
466 strlen(testcode), testcode));
467 if(glGetError() != 0) {
468 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
469 TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
470 ret = TRUE;
471 } else TRACE("OpenGL implementation allows offsets > 63\n");
473 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
474 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
475 checkGLcall("ARB vp offset limit test cleanup\n");
477 return ret;
480 static DWORD ver_for_ext(GL_SupportedExt ext)
482 unsigned int i;
483 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
484 if(EXTENSION_MAP[i].extension == ext) {
485 return EXTENSION_MAP[i].version;
488 return 0;
491 BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
492 const char *GL_Extensions = NULL;
493 const char *WGL_Extensions = NULL;
494 const char *gl_string = NULL;
495 const char *gl_string_cursor = NULL;
496 GLint gl_max;
497 GLfloat gl_floatv[2];
498 int major = 1, minor = 0;
499 BOOL return_value = TRUE;
500 unsigned i;
501 HDC hdc;
502 unsigned int vidmem=0;
504 TRACE_(d3d_caps)("(%p)\n", gl_info);
506 ENTER_GL();
508 gl_string = (const char *) glGetString(GL_RENDERER);
509 if (NULL == gl_string)
510 gl_string = "None";
511 strcpy(gl_info->gl_renderer, gl_string);
513 gl_string = (const char *) glGetString(GL_VENDOR);
514 TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
515 if (gl_string != NULL) {
516 /* Fill in the GL vendor */
517 if (strstr(gl_string, "NVIDIA")) {
518 gl_info->gl_vendor = VENDOR_NVIDIA;
519 } else if (strstr(gl_string, "ATI")) {
520 gl_info->gl_vendor = VENDOR_ATI;
521 } else if (strstr(gl_string, "Intel(R)") ||
522 strstr(gl_info->gl_renderer, "Intel(R)") ||
523 strstr(gl_string, "Intel Inc.")) {
524 gl_info->gl_vendor = VENDOR_INTEL;
525 } else if (strstr(gl_string, "Mesa")) {
526 gl_info->gl_vendor = VENDOR_MESA;
527 } else {
528 gl_info->gl_vendor = VENDOR_WINE;
530 } else {
531 gl_info->gl_vendor = VENDOR_WINE;
535 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
537 /* Parse the GL_VERSION field into major and minor information */
538 gl_string = (const char *) glGetString(GL_VERSION);
539 if (gl_string != NULL) {
541 /* First, parse the generic opengl version. This is supposed not to be convoluted with
542 * driver specific information
544 gl_string_cursor = gl_string;
545 major = atoi(gl_string_cursor);
546 if(major <= 0) {
547 ERR("Invalid opengl major version: %d\n", major);
549 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
550 ++gl_string_cursor;
552 if (*gl_string_cursor++ != '.') {
553 ERR_(d3d_caps)("Invalid opengl version string: %s\n", debugstr_a(gl_string));
555 minor = atoi(gl_string_cursor);
556 TRACE_(d3d_caps)("Found OpenGL version: %d.%d\n", major, minor);
557 gl_info->gl_version = MAKEDWORD_VERSION(major, minor);
559 /* Now parse the driver specific string which we'll report to the app */
560 switch (gl_info->gl_vendor) {
561 case VENDOR_NVIDIA:
562 gl_string_cursor = strstr(gl_string, "NVIDIA");
563 if (!gl_string_cursor) {
564 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
565 break;
568 gl_string_cursor = strstr(gl_string_cursor, " ");
569 if (!gl_string_cursor) {
570 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
571 break;
574 while (*gl_string_cursor == ' ') {
575 ++gl_string_cursor;
578 if (!*gl_string_cursor) {
579 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
580 break;
583 major = atoi(gl_string_cursor);
584 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
585 ++gl_string_cursor;
588 if (*gl_string_cursor++ != '.') {
589 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
590 break;
593 minor = atoi(gl_string_cursor);
594 minor = major*100+minor;
595 major = 10;
597 break;
599 case VENDOR_ATI:
600 major = minor = 0;
601 gl_string_cursor = strchr(gl_string, '-');
602 if (gl_string_cursor) {
603 int error = 0;
604 gl_string_cursor++;
606 /* Check if version number is of the form x.y.z */
607 if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
608 error = 1;
609 if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
610 error = 1;
611 if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
612 error = 1;
613 if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
614 error = 1;
616 /* Mark version number as malformed */
617 if (error)
618 gl_string_cursor = 0;
621 if (!gl_string_cursor)
622 WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
623 else {
624 major = *gl_string_cursor - '0';
625 minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
627 break;
629 case VENDOR_INTEL:
630 /* Apple and Mesa version strings look differently, but both provide intel drivers */
631 if(strstr(gl_string, "APPLE")) {
632 /* [0-9]+.[0-9]+ APPLE-[0-9]+.[0.9]+.[0.9]+
633 * We only need the first part, and use the APPLE as identification
634 * "1.2 APPLE-1.4.56"
636 gl_string_cursor = gl_string;
637 major = atoi(gl_string_cursor);
638 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
639 ++gl_string_cursor;
642 if (*gl_string_cursor++ != '.') {
643 ERR_(d3d_caps)("Invalid MacOS-Intel version string: %s\n", debugstr_a(gl_string));
644 break;
647 minor = atoi(gl_string_cursor);
648 break;
651 case VENDOR_MESA:
652 gl_string_cursor = strstr(gl_string, "Mesa");
653 gl_string_cursor = strstr(gl_string_cursor, " ");
654 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
655 if (*gl_string_cursor) {
656 char tmp[16];
657 int cursor = 0;
659 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
660 tmp[cursor++] = *gl_string_cursor;
661 ++gl_string_cursor;
663 tmp[cursor] = 0;
664 major = atoi(tmp);
666 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
667 ++gl_string_cursor;
669 cursor = 0;
670 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
671 tmp[cursor++] = *gl_string_cursor;
672 ++gl_string_cursor;
674 tmp[cursor] = 0;
675 minor = atoi(tmp);
677 break;
679 default:
680 major = 0;
681 minor = 9;
683 gl_info->driver_version = MAKEDWORD_VERSION(major, minor);
684 TRACE_(d3d_caps)("found driver version (%s)->%i.%i->(0x%08x)\n", debugstr_a(gl_string), major, minor, gl_info->driver_version);
685 /* Current Windows drivers have versions like 6.14.... (some older have an earlier version) */
686 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
687 } else {
688 FIXME("OpenGL driver did not return version information\n");
689 gl_info->driver_version = MAKEDWORD_VERSION(0, 0);
690 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
693 TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
696 * Initialize openGL extension related variables
697 * with Default values
699 memset(&gl_info->supported, 0, sizeof(gl_info->supported));
700 gl_info->max_buffers = 1;
701 gl_info->max_textures = 1;
702 gl_info->max_texture_stages = 1;
703 gl_info->max_fragment_samplers = 1;
704 gl_info->max_vertex_samplers = 0;
705 gl_info->max_combined_samplers = 0;
706 gl_info->max_sampler_stages = 1;
707 gl_info->ps_arb_version = PS_VERSION_NOT_SUPPORTED;
708 gl_info->ps_arb_max_temps = 0;
709 gl_info->ps_arb_max_instructions = 0;
710 gl_info->vs_arb_version = VS_VERSION_NOT_SUPPORTED;
711 gl_info->vs_arb_max_temps = 0;
712 gl_info->vs_arb_max_instructions = 0;
713 gl_info->vs_nv_version = VS_VERSION_NOT_SUPPORTED;
714 gl_info->vs_ati_version = VS_VERSION_NOT_SUPPORTED;
715 gl_info->vs_glsl_constantsF = 0;
716 gl_info->ps_glsl_constantsF = 0;
717 gl_info->vs_arb_constantsF = 0;
718 gl_info->ps_arb_constantsF = 0;
720 /* Retrieve opengl defaults */
721 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
722 gl_info->max_clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
723 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
725 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
726 gl_info->max_lights = gl_max;
727 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
729 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
730 gl_info->max_texture_size = gl_max;
731 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
733 glGetFloatv(GL_POINT_SIZE_RANGE, gl_floatv);
734 gl_info->max_pointsizemin = gl_floatv[0];
735 gl_info->max_pointsize = gl_floatv[1];
736 TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
738 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
739 GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
740 TRACE_(d3d_caps)("GL_Extensions reported:\n");
742 if (NULL == GL_Extensions) {
743 ERR(" GL_Extensions returns NULL\n");
744 } else {
745 while (*GL_Extensions != 0x00) {
746 const char *Start;
747 char ThisExtn[256];
748 size_t len;
750 while (isspace(*GL_Extensions)) GL_Extensions++;
751 Start = GL_Extensions;
752 while (!isspace(*GL_Extensions) && *GL_Extensions != 0x00) {
753 GL_Extensions++;
756 len = GL_Extensions - Start;
757 if (len == 0 || len >= sizeof(ThisExtn))
758 continue;
760 memcpy(ThisExtn, Start, len);
761 ThisExtn[len] = '\0';
762 TRACE_(d3d_caps)("- %s\n", ThisExtn);
764 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
765 if (!strcmp(ThisExtn, EXTENSION_MAP[i].extension_string)) {
766 TRACE_(d3d_caps)(" FOUND: %s support\n", EXTENSION_MAP[i].extension_string);
767 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
768 break;
772 /* Now work out what GL support this card really has */
773 #define USE_GL_FUNC(type, pfn, ext, replace) { \
774 DWORD ver = ver_for_ext(ext); \
775 if(gl_info->supported[ext]) gl_info->pfn = (type) pwglGetProcAddress(#pfn); \
776 else if(ver && ver <= gl_info->gl_version) gl_info->pfn = (type) pwglGetProcAddress(#replace); \
777 else gl_info->pfn = NULL; \
779 GL_EXT_FUNCS_GEN;
780 #undef USE_GL_FUNC
782 #define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type) pwglGetProcAddress(#pfn);
783 WGL_EXT_FUNCS_GEN;
784 #undef USE_GL_FUNC
786 /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
787 * loading the functions, otherwise the code above will load the extension entry points instead of the
788 * core functions, which may not work
790 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
791 if (gl_info->supported[EXTENSION_MAP[i].extension] == FALSE &&
792 EXTENSION_MAP[i].version <= gl_info->gl_version && EXTENSION_MAP[i].version) {
793 TRACE_(d3d_caps)(" GL CORE: %s support\n", EXTENSION_MAP[i].extension_string);
794 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
798 if (gl_info->supported[APPLE_FENCE]) {
799 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
800 * The apple extension interacts with some other apple exts. Disable the NV
801 * extension if the apple one is support to prevent confusion in other parts
802 * of the code
804 gl_info->supported[NV_FENCE] = FALSE;
806 if (gl_info->supported[APPLE_FLOAT_PIXELS]) {
807 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
809 * The enums are the same:
810 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881A
811 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881B
812 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
813 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
814 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140B
816 if(!gl_info->supported[ARB_TEXTURE_FLOAT]) {
817 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels\n");
818 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
820 if(!gl_info->supported[ARB_HALF_FLOAT_PIXEL]) {
821 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels\n");
822 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
825 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) {
826 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
827 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
829 if (gl_info->supported[NV_TEXTURE_SHADER2]) {
830 /* GL_ATI_envmap_bumpmap won't play nice with texture shaders, so disable it
831 * Won't occur in any real world situation though
833 gl_info->supported[ATI_ENVMAP_BUMPMAP] = FALSE;
834 if(gl_info->supported[NV_REGISTER_COMBINERS]) {
835 /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
836 * are supported. The nv extensions provide the same functionality as the
837 * ATI one, and a bit more(signed pixelformats)
839 gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
842 if (gl_info->supported[ARB_DRAW_BUFFERS]) {
843 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
844 gl_info->max_buffers = gl_max;
845 TRACE_(d3d_caps)("Max draw buffers: %u\n", gl_max);
847 if (gl_info->supported[ARB_MULTITEXTURE]) {
848 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
849 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
850 TRACE_(d3d_caps)("Max textures: %d\n", gl_info->max_textures);
852 if (gl_info->supported[NV_REGISTER_COMBINERS]) {
853 GLint tmp;
854 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &tmp);
855 gl_info->max_texture_stages = min(MAX_TEXTURES, tmp);
856 } else {
857 gl_info->max_texture_stages = min(MAX_TEXTURES, gl_max);
859 TRACE_(d3d_caps)("Max texture stages: %d\n", gl_info->max_texture_stages);
861 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
862 GLint tmp;
863 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
864 gl_info->max_fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
865 } else {
866 gl_info->max_fragment_samplers = max(gl_info->max_fragment_samplers, gl_max);
868 TRACE_(d3d_caps)("Max fragment samplers: %d\n", gl_info->max_fragment_samplers);
870 if (gl_info->supported[ARB_VERTEX_SHADER]) {
871 GLint tmp;
872 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
873 gl_info->max_vertex_samplers = tmp;
874 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
875 gl_info->max_combined_samplers = tmp;
877 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
878 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
879 * an issue because then the sampler setup only depends on the two shaders. If a pixel
880 * shader is used with fixed function vertex processing we're fine too because fixed function
881 * vertex processing doesn't use any samplers. If fixed function fragment processing is
882 * used we have to make sure that all vertex sampler setups are valid together with all
883 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
884 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
885 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
886 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
887 * a fixed function pipeline anymore.
889 * So this is just a check to check that our assumption holds true. If not, write a warning
890 * and reduce the number of vertex samplers or probably disable vertex texture fetch.
892 if(gl_info->max_vertex_samplers &&
893 MAX_TEXTURES + gl_info->max_vertex_samplers > gl_info->max_combined_samplers) {
894 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers\n",
895 gl_info->max_vertex_samplers, gl_info->max_combined_samplers);
896 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers\n");
897 if( gl_info->max_combined_samplers > MAX_TEXTURES )
898 gl_info->max_vertex_samplers =
899 gl_info->max_combined_samplers - MAX_TEXTURES;
900 else
901 gl_info->max_vertex_samplers = 0;
903 } else {
904 gl_info->max_combined_samplers = gl_info->max_fragment_samplers;
906 TRACE_(d3d_caps)("Max vertex samplers: %u\n", gl_info->max_vertex_samplers);
907 TRACE_(d3d_caps)("Max combined samplers: %u\n", gl_info->max_combined_samplers);
909 if (gl_info->supported[ARB_VERTEX_BLEND]) {
910 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
911 gl_info->max_blends = gl_max;
912 TRACE_(d3d_caps)("Max blends: %u\n", gl_info->max_blends);
914 if (gl_info->supported[EXT_TEXTURE3D]) {
915 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
916 gl_info->max_texture3d_size = gl_max;
917 TRACE_(d3d_caps)("Max texture3D size: %d\n", gl_info->max_texture3d_size);
919 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC]) {
920 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
921 gl_info->max_anisotropy = gl_max;
922 TRACE_(d3d_caps)("Max anisotropy: %d\n", gl_info->max_anisotropy);
924 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
925 gl_info->ps_arb_version = PS_VERSION_11;
926 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
927 gl_info->ps_arb_constantsF = gl_max;
928 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d\n", gl_info->ps_arb_constantsF);
929 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
930 gl_info->ps_arb_max_temps = gl_max;
931 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d\n", gl_info->ps_arb_max_temps);
932 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
933 gl_info->ps_arb_max_instructions = gl_max;
934 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d\n", gl_info->ps_arb_max_instructions);
936 if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
937 gl_info->vs_arb_version = VS_VERSION_11;
938 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
939 gl_info->vs_arb_constantsF = gl_max;
940 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d\n", gl_info->vs_arb_constantsF);
941 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
942 gl_info->vs_arb_max_temps = gl_max;
943 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d\n", gl_info->vs_arb_max_temps);
944 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
945 gl_info->vs_arb_max_instructions = gl_max;
946 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d\n", gl_info->vs_arb_max_instructions);
948 gl_info->arb_vs_offset_limit = test_arb_vs_offset_limit(gl_info);
950 if (gl_info->supported[ARB_VERTEX_SHADER]) {
951 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
952 gl_info->vs_glsl_constantsF = gl_max / 4;
953 TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u\n", gl_info->vs_glsl_constantsF);
955 if (gl_info->supported[ARB_FRAGMENT_SHADER]) {
956 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
957 gl_info->ps_glsl_constantsF = gl_max / 4;
958 TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u\n", gl_info->ps_glsl_constantsF);
959 glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
960 gl_info->max_glsl_varyings = gl_max;
961 TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings)\n", gl_max, gl_max / 4);
963 if (gl_info->supported[EXT_VERTEX_SHADER]) {
964 gl_info->vs_ati_version = VS_VERSION_11;
966 if (gl_info->supported[NV_VERTEX_PROGRAM3]) {
967 gl_info->vs_nv_version = VS_VERSION_30;
968 } else if (gl_info->supported[NV_VERTEX_PROGRAM2]) {
969 gl_info->vs_nv_version = VS_VERSION_20;
970 } else if (gl_info->supported[NV_VERTEX_PROGRAM1_1]) {
971 gl_info->vs_nv_version = VS_VERSION_11;
972 } else if (gl_info->supported[NV_VERTEX_PROGRAM]) {
973 gl_info->vs_nv_version = VS_VERSION_10;
975 if (gl_info->supported[NV_FRAGMENT_PROGRAM2]) {
976 gl_info->ps_nv_version = PS_VERSION_30;
977 } else if (gl_info->supported[NV_FRAGMENT_PROGRAM]) {
978 gl_info->ps_nv_version = PS_VERSION_20;
980 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT]) {
981 glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->max_shininess);
982 } else {
983 gl_info->max_shininess = 128.0;
985 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO]) {
986 /* If we have full NP2 texture support, disable GL_ARB_texture_rectangle because we will never use it.
987 * This saves a few redundant glDisable calls
989 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
991 if(gl_info->supported[ATI_FRAGMENT_SHADER]) {
992 /* Disable NV_register_combiners and fragment shader if this is supported.
993 * generally the NV extensions are preferred over the ATI ones, and this
994 * extension is disabled if register_combiners and texture_shader2 are both
995 * supported. So we reach this place only if we have incomplete NV dxlevel 8
996 * fragment processing support
998 gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
999 gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
1000 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
1001 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
1002 gl_info->supported[NV_TEXTURE_SHADER3] = FALSE;
1006 checkGLcall("extension detection\n");
1008 /* In some cases the number of texture stages can be larger than the number
1009 * of samplers. The GF4 for example can use only 2 samplers (no fragment
1010 * shaders), but 8 texture stages (register combiners). */
1011 gl_info->max_sampler_stages = max(gl_info->max_fragment_samplers, gl_info->max_texture_stages);
1013 /* We can only use ORM_FBO when the hardware supports it. */
1014 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && !gl_info->supported[EXT_FRAMEBUFFER_OBJECT]) {
1015 WARN_(d3d_caps)("GL_EXT_framebuffer_object not supported, falling back to PBuffer offscreen rendering mode.\n");
1016 wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
1019 /* MRTs are currently only supported when FBOs are used. */
1020 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) {
1021 gl_info->max_buffers = 1;
1024 /* Below is a list of Nvidia and ATI GPUs. Both vendors have dozens of different GPUs with roughly the same
1025 * features. In most cases GPUs from a certain family differ in clockspeeds, the amount of video memory and
1026 * in case of the latest videocards in the number of pixel/vertex pipelines.
1028 * A Direct3D device object contains the PCI id (vendor + device) of the videocard which is used for
1029 * rendering. Various games use this information to get a rough estimation of the features of the card
1030 * and some might use it for enabling 3d effects only on certain types of videocards. In some cases
1031 * games might even use it to work around bugs which happen on certain videocards/driver combinations.
1032 * The problem is that OpenGL only exposes a rendering string containing the name of the videocard and
1033 * not the PCI id.
1035 * Various games depend on the PCI id, so somehow we need to provide one. A simple option is to parse
1036 * the renderer string and translate this to the right PCI id. This is a lot of work because there are more
1037 * than 200 GPUs just for Nvidia. Various cards share the same renderer string, so the amount of code might
1038 * be 'small' but there are quite a number of exceptions which would make this a pain to maintain.
1039 * Another way would be to query the PCI id from the operating system (assuming this is the videocard which
1040 * is used for rendering which is not always the case). This would work but it is not very portable. Second
1041 * it would not work well in, let's say, a remote X situation in which the amount of 3d features which can be used
1042 * is limited.
1044 * As said most games only use the PCI id to get an indication of the capabilities of the card.
1045 * It doesn't really matter if the given id is the correct one if we return the id of a card with
1046 * similar 3d features.
1048 * The code below checks the OpenGL capabilities of a videocard and matches that to a certain level of
1049 * Direct3D functionality. Once a card passes the Direct3D9 check, we know that the card (in case of Nvidia)
1050 * is at least a GeforceFX. To give a better estimate we do a basic check on the renderer string but if that
1051 * won't pass we return a default card. This way is better than maintaining a full card database as even
1052 * without a full database we can return a card with similar features. Second the size of the database
1053 * can be made quite small because when you know what type of 3d functionality a card has, you know to which
1054 * GPU family the GPU must belong. Because of this you only have to check a small part of the renderer string
1055 * to distinguishes between different models from that family.
1057 * The code also selects a default amount of video memory which we will use for an estimation of the amount
1058 * of free texture memory. In case of real D3D the amount of texture memory includes video memory and system
1059 * memory (to be specific AGP memory or in case of PCIE TurboCache/HyperMemory). We don't know how much
1060 * system memory can be addressed by the system but we can make a reasonable estimation about the amount of
1061 * video memory. If the value is slightly wrong it doesn't matter as we didn't include AGP-like memory which
1062 * makes the amount of addressable memory higher and second OpenGL isn't that critical it moves to system
1063 * memory behind our backs if really needed.
1064 * Note that the amount of video memory can be overruled using a registry setting.
1066 switch (gl_info->gl_vendor) {
1067 case VENDOR_NVIDIA:
1068 /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1069 * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1071 if(WINE_D3D9_CAPABLE(gl_info) && (gl_info->vs_nv_version == VS_VERSION_30)) {
1072 /* Geforce9 - highend */
1073 if(strstr(gl_info->gl_renderer, "9800")) {
1074 gl_info->gl_card = CARD_NVIDIA_GEFORCE_9800GT;
1075 vidmem = 512;
1077 /* Geforce9 - midend */
1078 else if(strstr(gl_info->gl_renderer, "9600")) {
1079 gl_info->gl_card = CARD_NVIDIA_GEFORCE_9600GT;
1080 vidmem = 384; /* The 9600GSO has 384MB, the 9600GT has 512-1024MB */
1082 /* Geforce8 - highend */
1083 if (strstr(gl_info->gl_renderer, "8800")) {
1084 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8800GTS;
1085 vidmem = 320; /* The 8800GTS uses 320MB, a 8800GTX can have 768MB */
1087 /* Geforce8 - midend mobile */
1088 else if(strstr(gl_info->gl_renderer, "8600 M")) {
1089 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600MGT;
1090 vidmem = 512;
1092 /* Geforce8 - midend */
1093 else if(strstr(gl_info->gl_renderer, "8600") ||
1094 strstr(gl_info->gl_renderer, "8700"))
1096 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600GT;
1097 vidmem = 256;
1099 /* Geforce8 - lowend */
1100 else if(strstr(gl_info->gl_renderer, "8300") ||
1101 strstr(gl_info->gl_renderer, "8400") ||
1102 strstr(gl_info->gl_renderer, "8500"))
1104 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8300GS;
1105 vidmem = 128; /* 128-256MB for a 8300, 256-512MB for a 8400 */
1107 /* Geforce7 - highend */
1108 else if(strstr(gl_info->gl_renderer, "7800") ||
1109 strstr(gl_info->gl_renderer, "7900") ||
1110 strstr(gl_info->gl_renderer, "7950") ||
1111 strstr(gl_info->gl_renderer, "Quadro FX 4") ||
1112 strstr(gl_info->gl_renderer, "Quadro FX 5"))
1114 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7800GT;
1115 vidmem = 256; /* A 7800GT uses 256MB while highend 7900 cards can use 512MB */
1117 /* Geforce7 midend */
1118 else if(strstr(gl_info->gl_renderer, "7600") ||
1119 strstr(gl_info->gl_renderer, "7700")) {
1120 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7600;
1121 vidmem = 256; /* The 7600 uses 256-512MB */
1122 /* Geforce7 lower medium */
1123 } else if(strstr(gl_info->gl_renderer, "7400")) {
1124 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7400;
1125 vidmem = 256; /* The 7400 uses 256-512MB */
1127 /* Geforce7 lowend */
1128 else if(strstr(gl_info->gl_renderer, "7300")) {
1129 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7300;
1130 vidmem = 256; /* Mac Pros with this card have 256 MB */
1132 /* Geforce6 highend */
1133 else if(strstr(gl_info->gl_renderer, "6800"))
1135 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6800;
1136 vidmem = 128; /* The 6800 uses 128-256MB, the 7600 uses 256-512MB */
1138 /* Geforce6 - midend */
1139 else if(strstr(gl_info->gl_renderer, "6600") ||
1140 strstr(gl_info->gl_renderer, "6610") ||
1141 strstr(gl_info->gl_renderer, "6700"))
1143 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6600GT;
1144 vidmem = 128; /* A 6600GT has 128-256MB */
1146 /* Geforce6/7 lowend */
1147 else {
1148 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
1149 vidmem = 64; /* */
1151 } else if(WINE_D3D9_CAPABLE(gl_info)) {
1152 /* GeforceFX - highend */
1153 if (strstr(gl_info->gl_renderer, "5800") ||
1154 strstr(gl_info->gl_renderer, "5900") ||
1155 strstr(gl_info->gl_renderer, "5950") ||
1156 strstr(gl_info->gl_renderer, "Quadro FX"))
1158 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5800;
1159 vidmem = 256; /* 5800-5900 cards use 256MB */
1161 /* GeforceFX - midend */
1162 else if(strstr(gl_info->gl_renderer, "5600") ||
1163 strstr(gl_info->gl_renderer, "5650") ||
1164 strstr(gl_info->gl_renderer, "5700") ||
1165 strstr(gl_info->gl_renderer, "5750"))
1167 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1168 vidmem = 128; /* A 5600 uses 128-256MB */
1170 /* GeforceFX - lowend */
1171 else {
1172 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1173 vidmem = 64; /* Normal FX5200 cards use 64-256MB; laptop (non-standard) can have less */
1175 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1176 if (strstr(gl_info->gl_renderer, "GeForce4 Ti") || strstr(gl_info->gl_renderer, "Quadro4")) {
1177 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1178 vidmem = 64; /* Geforce4 Ti cards have 64-128MB */
1180 else {
1181 gl_info->gl_card = CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1182 vidmem = 64; /* Geforce3 cards have 64-128MB */
1184 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1185 if (strstr(gl_info->gl_renderer, "GeForce4 MX")) {
1186 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1187 vidmem = 64; /* Most Geforce4MX GPUs have at least 64MB of memory, some early models had 32MB but most have 64MB or even 128MB */
1189 else if(strstr(gl_info->gl_renderer, "GeForce2 MX") || strstr(gl_info->gl_renderer, "Quadro2 MXR")) {
1190 gl_info->gl_card = CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1191 vidmem = 32; /* Geforce2MX GPUs have 32-64MB of video memory */
1193 else if(strstr(gl_info->gl_renderer, "GeForce2") || strstr(gl_info->gl_renderer, "Quadro2")) {
1194 gl_info->gl_card = CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1195 vidmem = 32; /* Geforce2 GPUs have 32-64MB of video memory */
1197 else {
1198 gl_info->gl_card = CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1199 vidmem = 32; /* Most Geforce1 cards have 32MB, there are also some rare 16 and 64MB (Dell) models */
1201 } else {
1202 if (strstr(gl_info->gl_renderer, "TNT2")) {
1203 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1204 vidmem = 32; /* Most TNT2 boards have 32MB, though there are 16MB boards too */
1206 else {
1207 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1208 vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
1211 break;
1212 case VENDOR_ATI:
1213 if(WINE_D3D9_CAPABLE(gl_info)) {
1214 /* Radeon R6xx HD2900 - highend */
1215 if (strstr(gl_info->gl_renderer, "HD 2900")) {
1216 gl_info->gl_card = CARD_ATI_RADEON_HD2900;
1217 vidmem = 512; /* HD2900 uses 512-1024MB */
1219 /* Radeon R6xx HD2600- midend */
1220 else if (strstr(gl_info->gl_renderer, "HD 2600")) {
1221 gl_info->gl_card = CARD_ATI_RADEON_HD2600;
1222 vidmem = 256; /* HD2600 uses 256-512MB */
1224 /* Radeon R6xx HD2300/HD2400 - lowend */
1225 else if (strstr(gl_info->gl_renderer, "HD 2300") ||
1226 strstr(gl_info->gl_renderer, "HD 2400"))
1228 gl_info->gl_card = CARD_ATI_RADEON_HD2300;
1229 vidmem = 128; /* HD2300 uses at least 128MB, HD2400 uses 256MB */
1231 /* Radeon R5xx */
1232 else if (strstr(gl_info->gl_renderer, "X1600") ||
1233 strstr(gl_info->gl_renderer, "X1650") ||
1234 strstr(gl_info->gl_renderer, "X1800") ||
1235 strstr(gl_info->gl_renderer, "X1900") ||
1236 strstr(gl_info->gl_renderer, "X1950"))
1238 gl_info->gl_card = CARD_ATI_RADEON_X1600;
1239 vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
1241 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
1242 else if(strstr(gl_info->gl_renderer, "X700") ||
1243 strstr(gl_info->gl_renderer, "X800") ||
1244 strstr(gl_info->gl_renderer, "X850") ||
1245 strstr(gl_info->gl_renderer, "X1300") ||
1246 strstr(gl_info->gl_renderer, "X1400") ||
1247 strstr(gl_info->gl_renderer, "X1450") ||
1248 strstr(gl_info->gl_renderer, "X1550"))
1250 gl_info->gl_card = CARD_ATI_RADEON_X700;
1251 vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
1253 /* Radeon R3xx */
1254 else {
1255 gl_info->gl_card = CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
1256 vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
1258 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1259 gl_info->gl_card = CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
1260 vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
1261 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1262 gl_info->gl_card = CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
1263 vidmem = 32; /* There are models with up to 64MB */
1264 } else {
1265 gl_info->gl_card = CARD_ATI_RAGE_128PRO;
1266 vidmem = 16; /* There are 16-32MB models */
1268 break;
1269 case VENDOR_INTEL:
1270 if (strstr(gl_info->gl_renderer, "GMA 950")) {
1271 /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */
1272 gl_info->gl_card = CARD_INTEL_I945GM;
1273 vidmem = 64;
1274 } else if (strstr(gl_info->gl_renderer, "915GM")) {
1275 gl_info->gl_card = CARD_INTEL_I915GM;
1276 } else if (strstr(gl_info->gl_renderer, "915G")) {
1277 gl_info->gl_card = CARD_INTEL_I915G;
1278 } else if (strstr(gl_info->gl_renderer, "865G")) {
1279 gl_info->gl_card = CARD_INTEL_I865G;
1280 } else if (strstr(gl_info->gl_renderer, "855G")) {
1281 gl_info->gl_card = CARD_INTEL_I855G;
1282 } else if (strstr(gl_info->gl_renderer, "830G")) {
1283 gl_info->gl_card = CARD_INTEL_I830G;
1284 } else {
1285 gl_info->gl_card = CARD_INTEL_I915G;
1287 break;
1288 case VENDOR_MESA:
1289 case VENDOR_WINE:
1290 default:
1291 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice
1292 * for Nvidia was because the hardware and drivers they make are of good quality. This makes
1293 * them a good generic choice.
1295 gl_info->gl_vendor = VENDOR_NVIDIA;
1296 if(WINE_D3D9_CAPABLE(gl_info))
1297 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1298 else if(WINE_D3D8_CAPABLE(gl_info))
1299 gl_info->gl_card = CARD_NVIDIA_GEFORCE3;
1300 else if(WINE_D3D7_CAPABLE(gl_info))
1301 gl_info->gl_card = CARD_NVIDIA_GEFORCE;
1302 else if(WINE_D3D6_CAPABLE(gl_info))
1303 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT;
1304 else
1305 gl_info->gl_card = CARD_NVIDIA_RIVA_128;
1307 TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card);
1309 /* If we have an estimate use it, else default to 64MB; */
1310 if(vidmem)
1311 gl_info->vidmem = vidmem*1024*1024; /* convert from MBs to bytes */
1312 else
1313 gl_info->vidmem = WINE_DEFAULT_VIDMEM;
1315 /* Load all the lookup tables
1316 TODO: It may be a good idea to make minLookup and maxLookup const and populate them in wined3d_private.h where they are declared */
1317 minLookup[WINELOOKUP_WARPPARAM] = WINED3DTADDRESS_WRAP;
1318 maxLookup[WINELOOKUP_WARPPARAM] = WINED3DTADDRESS_MIRRORONCE;
1320 for (i = 0; i < MAX_LOOKUPS; i++) {
1321 stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
1324 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
1325 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
1326 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1327 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1328 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1329 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1330 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
1331 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
1332 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
1333 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
1335 magLookup[WINED3DTEXF_NONE - WINED3DTEXF_NONE] = GL_NEAREST;
1336 magLookup[WINED3DTEXF_POINT - WINED3DTEXF_NONE] = GL_NEAREST;
1337 magLookup[WINED3DTEXF_LINEAR - WINED3DTEXF_NONE] = GL_LINEAR;
1338 magLookup[WINED3DTEXF_ANISOTROPIC - WINED3DTEXF_NONE] =
1339 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR : GL_NEAREST;
1342 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_NONE] = GL_LINEAR;
1343 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_POINT] = GL_LINEAR;
1344 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_LINEAR] = GL_LINEAR;
1345 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_NONE] = GL_NEAREST;
1346 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_POINT] = GL_NEAREST_MIPMAP_NEAREST;
1347 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_LINEAR] = GL_NEAREST_MIPMAP_LINEAR;
1348 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_NONE] = GL_LINEAR;
1349 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_POINT] = GL_LINEAR_MIPMAP_NEAREST;
1350 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_LINEAR] = GL_LINEAR_MIPMAP_LINEAR;
1351 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_NONE] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ?
1352 GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1353 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_POINT] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR;
1354 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_LINEAR] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1356 /* TODO: config lookups */
1358 /* Make sure there's an active HDC else the WGL extensions will fail */
1359 hdc = pwglGetCurrentDC();
1360 if (hdc) {
1361 WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc));
1362 TRACE_(d3d_caps)("WGL_Extensions reported:\n");
1364 if (NULL == WGL_Extensions) {
1365 ERR(" WGL_Extensions returns NULL\n");
1366 } else {
1367 while (*WGL_Extensions != 0x00) {
1368 const char *Start;
1369 char ThisExtn[256];
1370 size_t len;
1372 while (isspace(*WGL_Extensions)) WGL_Extensions++;
1373 Start = WGL_Extensions;
1374 while (!isspace(*WGL_Extensions) && *WGL_Extensions != 0x00) {
1375 WGL_Extensions++;
1378 len = WGL_Extensions - Start;
1379 if (len == 0 || len >= sizeof(ThisExtn))
1380 continue;
1382 memcpy(ThisExtn, Start, len);
1383 ThisExtn[len] = '\0';
1384 TRACE_(d3d_caps)("- %s\n", ThisExtn);
1386 if (!strcmp(ThisExtn, "WGL_ARB_pbuffer")) {
1387 gl_info->supported[WGL_ARB_PBUFFER] = TRUE;
1388 TRACE_(d3d_caps)("FOUND: WGL_ARB_pbuffer support\n");
1390 if (!strcmp(ThisExtn, "WGL_WINE_pixel_format_passthrough")) {
1391 gl_info->supported[WGL_WINE_PIXEL_FORMAT_PASSTHROUGH] = TRUE;
1392 TRACE_(d3d_caps)("FOUND: WGL_WINE_pixel_format_passthrough support\n");
1397 LEAVE_GL();
1399 return return_value;
1401 #undef GLINFO_LOCATION
1403 /**********************************************************
1404 * IWineD3D implementation follows
1405 **********************************************************/
1407 static UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
1408 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1410 TRACE_(d3d_caps)("(%p): Reporting %d adapters\n", This, numAdapters);
1411 return numAdapters;
1414 static HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
1415 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1416 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
1417 return WINED3D_OK;
1420 static HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
1421 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1423 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
1424 return NULL;
1427 TRACE_(d3d_caps)("(%p)->(%d)\n", This, Adapter);
1428 return MonitorFromPoint(Adapters[Adapter].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
1431 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
1432 of the same bpp but different resolutions */
1434 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1435 static UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
1436 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1437 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
1439 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1440 return 0;
1443 /* TODO: Store modes per adapter and read it from the adapter structure */
1444 if (Adapter == 0) { /* Display */
1445 int i = 0;
1446 int j = 0;
1448 if (!DEBUG_SINGLE_MODE) {
1449 DEVMODEW DevModeW;
1451 ZeroMemory(&DevModeW, sizeof(DevModeW));
1452 DevModeW.dmSize = sizeof(DevModeW);
1453 while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
1454 j++;
1455 switch (Format)
1457 case WINED3DFMT_UNKNOWN:
1458 /* This is for D3D8, do not enumerate P8 here */
1459 if (DevModeW.dmBitsPerPel == 32 ||
1460 DevModeW.dmBitsPerPel == 16) i++;
1461 break;
1462 case WINED3DFMT_X8R8G8B8:
1463 if (DevModeW.dmBitsPerPel == 32) i++;
1464 break;
1465 case WINED3DFMT_R5G6B5:
1466 if (DevModeW.dmBitsPerPel == 16) i++;
1467 break;
1468 case WINED3DFMT_P8:
1469 if (DevModeW.dmBitsPerPel == 8) i++;
1470 break;
1471 default:
1472 /* Skip other modes as they do not match the requested format */
1473 break;
1476 } else {
1477 i = 1;
1478 j = 1;
1481 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
1482 return i;
1483 } else {
1484 FIXME_(d3d_caps)("Adapter not primary display\n");
1486 return 0;
1489 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1490 static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, WINED3DDISPLAYMODE* pMode) {
1491 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1492 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
1494 /* Validate the parameters as much as possible */
1495 if (NULL == pMode ||
1496 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
1497 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
1498 return WINED3DERR_INVALIDCALL;
1501 /* TODO: Store modes per adapter and read it from the adapter structure */
1502 if (Adapter == 0 && !DEBUG_SINGLE_MODE) { /* Display */
1503 DEVMODEW DevModeW;
1504 int ModeIdx = 0;
1505 int i = 0;
1506 int j = 0;
1508 ZeroMemory(&DevModeW, sizeof(DevModeW));
1509 DevModeW.dmSize = sizeof(DevModeW);
1511 /* If we are filtering to a specific format (D3D9), then need to skip
1512 all unrelated modes, but if mode is irrelevant (D3D8), then we can
1513 just count through the ones with valid bit depths */
1514 while ((i<=Mode) && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0)) {
1515 switch (Format)
1517 case WINED3DFMT_UNKNOWN:
1518 /* This is D3D8. Do not enumerate P8 here */
1519 if (DevModeW.dmBitsPerPel == 32 ||
1520 DevModeW.dmBitsPerPel == 16) i++;
1521 break;
1522 case WINED3DFMT_X8R8G8B8:
1523 if (DevModeW.dmBitsPerPel == 32) i++;
1524 break;
1525 case WINED3DFMT_R5G6B5:
1526 if (DevModeW.dmBitsPerPel == 16) i++;
1527 break;
1528 case WINED3DFMT_P8:
1529 if (DevModeW.dmBitsPerPel == 8) i++;
1530 break;
1531 default:
1532 /* Modes that don't match what we support can get an early-out */
1533 TRACE_(d3d_caps)("Searching for %s, returning D3DERR_INVALIDCALL\n", debug_d3dformat(Format));
1534 return WINED3DERR_INVALIDCALL;
1538 if (i == 0) {
1539 TRACE_(d3d_caps)("No modes found for format (%x - %s)\n", Format, debug_d3dformat(Format));
1540 return WINED3DERR_INVALIDCALL;
1542 ModeIdx = j - 1;
1544 /* Now get the display mode via the calculated index */
1545 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0)) {
1546 pMode->Width = DevModeW.dmPelsWidth;
1547 pMode->Height = DevModeW.dmPelsHeight;
1548 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1549 if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
1550 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1552 if (Format == WINED3DFMT_UNKNOWN) {
1553 pMode->Format = pixelformat_for_depth(DevModeW.dmBitsPerPel);
1554 } else {
1555 pMode->Format = Format;
1557 } else {
1558 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
1559 return WINED3DERR_INVALIDCALL;
1562 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
1563 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format),
1564 DevModeW.dmBitsPerPel);
1566 } else if (DEBUG_SINGLE_MODE) {
1567 /* Return one setting of the format requested */
1568 if (Mode > 0) return WINED3DERR_INVALIDCALL;
1569 pMode->Width = 800;
1570 pMode->Height = 600;
1571 pMode->RefreshRate = 60;
1572 pMode->Format = (Format == WINED3DFMT_UNKNOWN) ? WINED3DFMT_X8R8G8B8 : Format;
1573 } else {
1574 FIXME_(d3d_caps)("Adapter not primary display\n");
1577 return WINED3D_OK;
1580 static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, WINED3DDISPLAYMODE* pMode) {
1581 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1582 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
1584 if (NULL == pMode ||
1585 Adapter >= IWineD3D_GetAdapterCount(iface)) {
1586 return WINED3DERR_INVALIDCALL;
1589 if (Adapter == 0) { /* Display */
1590 int bpp = 0;
1591 DEVMODEW DevModeW;
1593 ZeroMemory(&DevModeW, sizeof(DevModeW));
1594 DevModeW.dmSize = sizeof(DevModeW);
1596 EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &DevModeW, 0);
1597 pMode->Width = DevModeW.dmPelsWidth;
1598 pMode->Height = DevModeW.dmPelsHeight;
1599 bpp = DevModeW.dmBitsPerPel;
1600 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1601 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
1603 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1606 pMode->Format = pixelformat_for_depth(bpp);
1607 } else {
1608 FIXME_(d3d_caps)("Adapter not primary display\n");
1611 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
1612 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
1613 return WINED3D_OK;
1616 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
1617 and fields being inserted in the middle, a new structure is used in place */
1618 static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
1619 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
1620 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1622 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %x, pId=%p)\n", This, Adapter, Flags, pIdentifier);
1624 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1625 return WINED3DERR_INVALIDCALL;
1628 /* Return the information requested */
1629 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
1630 strcpy(pIdentifier->Driver, Adapters[Adapter].driver);
1631 strcpy(pIdentifier->Description, Adapters[Adapter].description);
1633 /* Note dx8 doesn't supply a DeviceName */
1634 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
1635 pIdentifier->DriverVersion->u.HighPart = Adapters[Adapter].gl_info.driver_version_hipart;
1636 pIdentifier->DriverVersion->u.LowPart = Adapters[Adapter].gl_info.driver_version;
1637 *(pIdentifier->VendorId) = Adapters[Adapter].gl_info.gl_vendor;
1638 *(pIdentifier->DeviceId) = Adapters[Adapter].gl_info.gl_card;
1639 *(pIdentifier->SubSysId) = 0;
1640 *(pIdentifier->Revision) = 0;
1641 *pIdentifier->DeviceIdentifier = IID_D3DDEVICE_D3DUID;
1643 if (Flags & WINED3DENUM_NO_WHQL_LEVEL) {
1644 *(pIdentifier->WHQLLevel) = 0;
1645 } else {
1646 *(pIdentifier->WHQLLevel) = 1;
1649 return WINED3D_OK;
1652 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const WineD3D_PixelFormat *cfg, WINED3DFORMAT Format) {
1653 short redSize, greenSize, blueSize, alphaSize, colorBits;
1655 if(!cfg)
1656 return FALSE;
1658 if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */
1659 if(!getColorBits(Format, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits)) {
1660 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(Format));
1661 return FALSE;
1664 if(cfg->redSize < redSize)
1665 return FALSE;
1667 if(cfg->greenSize < greenSize)
1668 return FALSE;
1670 if(cfg->blueSize < blueSize)
1671 return FALSE;
1673 if(cfg->alphaSize < alphaSize)
1674 return FALSE;
1676 return TRUE;
1677 } else if(cfg->iPixelType == WGL_TYPE_RGBA_FLOAT_ARB) { /* Float RGBA formats; TODO: WGL_NV_float_buffer */
1678 if(Format == WINED3DFMT_R16F)
1679 return (cfg->redSize == 16 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1680 if(Format == WINED3DFMT_G16R16F)
1681 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1682 if(Format == WINED3DFMT_A16B16G16R16F)
1683 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 16 && cfg->alphaSize == 16);
1684 if(Format == WINED3DFMT_R32F)
1685 return (cfg->redSize == 32 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1686 if(Format == WINED3DFMT_G32R32F)
1687 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1688 if(Format == WINED3DFMT_A32B32G32R32F)
1689 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 32 && cfg->alphaSize == 32);
1690 } else {
1691 /* Probably a color index mode */
1692 return FALSE;
1695 return FALSE;
1698 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const WineD3D_PixelFormat *cfg, WINED3DFORMAT Format) {
1699 short depthSize, stencilSize;
1700 BOOL lockable = FALSE;
1702 if(!cfg)
1703 return FALSE;
1705 if(!getDepthStencilBits(Format, &depthSize, &stencilSize)) {
1706 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(Format));
1707 return FALSE;
1710 if((Format == WINED3DFMT_D16_LOCKABLE) || (Format == WINED3DFMT_D32F_LOCKABLE))
1711 lockable = TRUE;
1713 /* On some modern cards like the Geforce8/9 GLX doesn't offer some dephthstencil formats which D3D9 reports.
1714 * We can safely report 'compatible' formats (e.g. D24 can be used for D16) as long as we aren't dealing with
1715 * a lockable format. This also helps D3D <= 7 as they expect D16 which isn't offered without this on Geforce8 cards. */
1716 if(!(cfg->depthSize == depthSize || (!lockable && cfg->depthSize > depthSize)))
1717 return FALSE;
1719 /* Some cards like Intel i915 ones only offer D24S8 but lots of games also need a format without stencil, so
1720 * allow more stencil bits than requested. */
1721 if(cfg->stencilSize < stencilSize)
1722 return FALSE;
1724 return TRUE;
1727 static HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1728 WINED3DFORMAT AdapterFormat,
1729 WINED3DFORMAT RenderTargetFormat,
1730 WINED3DFORMAT DepthStencilFormat) {
1731 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1732 int nCfgs;
1733 WineD3D_PixelFormat *cfgs;
1734 int it;
1736 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
1737 This, Adapter,
1738 DeviceType, debug_d3ddevicetype(DeviceType),
1739 AdapterFormat, debug_d3dformat(AdapterFormat),
1740 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
1741 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
1743 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1744 TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning WINED3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
1745 return WINED3DERR_INVALIDCALL;
1748 cfgs = Adapters[Adapter].cfgs;
1749 nCfgs = Adapters[Adapter].nCfgs;
1750 for (it = 0; it < nCfgs; ++it) {
1751 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], RenderTargetFormat)) {
1752 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&cfgs[it], DepthStencilFormat)) {
1753 TRACE_(d3d_caps)("(%p) : Formats matched\n", This);
1754 return WINED3D_OK;
1758 WARN_(d3d_caps)("unsupported format pair: %s and %s\n", debug_d3dformat(RenderTargetFormat), debug_d3dformat(DepthStencilFormat));
1760 return WINED3DERR_NOTAVAILABLE;
1763 static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1764 WINED3DFORMAT SurfaceFormat,
1765 BOOL Windowed, WINED3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
1767 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1768 const GlPixelFormatDesc *glDesc;
1769 const StaticPixelFormatDesc *desc;
1771 TRACE_(d3d_caps)("(%p)-> (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
1772 This,
1773 Adapter,
1774 DeviceType, debug_d3ddevicetype(DeviceType),
1775 SurfaceFormat, debug_d3dformat(SurfaceFormat),
1776 Windowed,
1777 MultiSampleType,
1778 pQualityLevels);
1780 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1781 return WINED3DERR_INVALIDCALL;
1784 /* TODO: handle Windowed, add more quality levels */
1786 if (WINED3DMULTISAMPLE_NONE == MultiSampleType) return WINED3D_OK;
1788 /* By default multisampling is disabled right now as it causes issues
1789 * on some Nvidia driver versions and it doesn't work well in combination
1790 * with FBOs yet. */
1791 if(!wined3d_settings.allow_multisampling)
1792 return WINED3DERR_NOTAVAILABLE;
1794 desc = getFormatDescEntry(SurfaceFormat, &Adapters[Adapter].gl_info, &glDesc);
1795 if(!desc || !glDesc) {
1796 return WINED3DERR_INVALIDCALL;
1799 if(glDesc->Flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)) {
1800 int i, nCfgs;
1801 WineD3D_PixelFormat *cfgs;
1803 cfgs = Adapters[Adapter].cfgs;
1804 nCfgs = Adapters[Adapter].nCfgs;
1805 for(i=0; i<nCfgs; i++) {
1806 if(cfgs[i].numSamples != MultiSampleType)
1807 continue;
1809 if(!IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&cfgs[i], SurfaceFormat))
1810 continue;
1812 TRACE("Found iPixelFormat=%d to support MultiSampleType=%d for format %s\n", cfgs[i].iPixelFormat, MultiSampleType, debug_d3dformat(SurfaceFormat));
1814 if(pQualityLevels)
1815 *pQualityLevels = 1; /* Guess at a value! */
1816 return WINED3D_OK;
1819 else if(glDesc->Flags & WINED3DFMT_FLAG_RENDERTARGET) {
1820 short redSize, greenSize, blueSize, alphaSize, colorBits;
1821 int i, nCfgs;
1822 WineD3D_PixelFormat *cfgs;
1824 if(!getColorBits(SurfaceFormat, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits)) {
1825 ERR("Unable to color bits for format %#x, can't check multisampling capability!\n", SurfaceFormat);
1826 return WINED3DERR_NOTAVAILABLE;
1829 cfgs = Adapters[Adapter].cfgs;
1830 nCfgs = Adapters[Adapter].nCfgs;
1831 for(i=0; i<nCfgs; i++) {
1832 if(cfgs[i].numSamples != MultiSampleType)
1833 continue;
1834 if(cfgs[i].redSize != redSize)
1835 continue;
1836 if(cfgs[i].greenSize != greenSize)
1837 continue;
1838 if(cfgs[i].blueSize != blueSize)
1839 continue;
1840 if(cfgs[i].alphaSize != alphaSize)
1841 continue;
1843 TRACE("Found iPixelFormat=%d to support MultiSampleType=%d for format %s\n", cfgs[i].iPixelFormat, MultiSampleType, debug_d3dformat(SurfaceFormat));
1845 if(pQualityLevels)
1846 *pQualityLevels = 1; /* Guess at a value! */
1847 return WINED3D_OK;
1850 return WINED3DERR_NOTAVAILABLE;
1853 static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1854 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
1856 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1857 HRESULT hr = WINED3DERR_NOTAVAILABLE;
1858 UINT nmodes;
1860 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
1861 This,
1862 Adapter,
1863 DeviceType, debug_d3ddevicetype(DeviceType),
1864 DisplayFormat, debug_d3dformat(DisplayFormat),
1865 BackBufferFormat, debug_d3dformat(BackBufferFormat),
1866 Windowed);
1868 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1869 WARN_(d3d_caps)("Adapter >= IWineD3D_GetAdapterCount(iface), returning WINED3DERR_INVALIDCALL\n");
1870 return WINED3DERR_INVALIDCALL;
1873 /* The task of this function is to check whether a certain display / backbuffer format
1874 * combination is available on the given adapter. In fullscreen mode microsoft specified
1875 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
1876 * and display format should match exactly.
1877 * In windowed mode format conversion can occur and this depends on the driver. When format
1878 * conversion is done, this function should nevertheless fail and applications need to use
1879 * CheckDeviceFormatConversion.
1880 * At the moment we assume that fullscreen and windowed have the same capabilities */
1882 /* There are only 4 display formats */
1883 if(!((DisplayFormat == WINED3DFMT_R5G6B5) ||
1884 (DisplayFormat == WINED3DFMT_X1R5G5B5) ||
1885 (DisplayFormat == WINED3DFMT_X8R8G8B8) ||
1886 (DisplayFormat == WINED3DFMT_A2R10G10B10)))
1888 TRACE_(d3d_caps)("Format %s unsupported as display format\n", debug_d3dformat(DisplayFormat));
1889 return WINED3DERR_NOTAVAILABLE;
1892 /* If the requested DisplayFormat is not available, don't continue */
1893 nmodes = IWineD3DImpl_GetAdapterModeCount(iface, Adapter, DisplayFormat);
1894 if(!nmodes) {
1895 TRACE_(d3d_caps)("No available modes for display format %s\n", debug_d3dformat(DisplayFormat));
1896 return WINED3DERR_NOTAVAILABLE;
1899 /* Windowed mode allows you to specify WINED3DFMT_UNKNOWN for the backbufferformat, it means 'reuse' the display format for the backbuffer */
1900 if(!Windowed && BackBufferFormat == WINED3DFMT_UNKNOWN) {
1901 TRACE_(d3d_caps)("BackBufferFormat WINED3FMT_UNKNOWN not available in Windowed mode\n");
1902 return WINED3DERR_NOTAVAILABLE;
1905 /* In FULLSCREEN mode R5G6B5 can only be mixed with backbuffer format R5G6B5 */
1906 if( (DisplayFormat == WINED3DFMT_R5G6B5) && (BackBufferFormat != WINED3DFMT_R5G6B5) ) {
1907 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1908 return WINED3DERR_NOTAVAILABLE;
1911 /* In FULLSCREEN mode X1R5G5B5 can only be mixed with backbuffer format *1R5G5B5 */
1912 if( (DisplayFormat == WINED3DFMT_X1R5G5B5) && !((BackBufferFormat == WINED3DFMT_X1R5G5B5) || (BackBufferFormat == WINED3DFMT_A1R5G5B5)) ) {
1913 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1914 return WINED3DERR_NOTAVAILABLE;
1917 /* In FULLSCREEN mode X8R8G8B8 can only be mixed with backbuffer format *8R8G8B8 */
1918 if( (DisplayFormat == WINED3DFMT_X8R8G8B8) && !((BackBufferFormat == WINED3DFMT_X8R8G8B8) || (BackBufferFormat == WINED3DFMT_A8R8G8B8)) ) {
1919 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1920 return WINED3DERR_NOTAVAILABLE;
1923 /* A2R10G10B10 is only allowed in fullscreen mode and it can only be mixed with backbuffer format A2R10G10B10 */
1924 if( (DisplayFormat == WINED3DFMT_A2R10G10B10) && ((BackBufferFormat != WINED3DFMT_A2R10G10B10) || Windowed)) {
1925 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1926 return WINED3DERR_NOTAVAILABLE;
1929 /* Use CheckDeviceFormat to see if the BackBufferFormat is usable with the given DisplayFormat */
1930 hr = IWineD3DImpl_CheckDeviceFormat(iface, Adapter, DeviceType, DisplayFormat, WINED3DUSAGE_RENDERTARGET, WINED3DRTYPE_SURFACE, BackBufferFormat);
1931 if(FAILED(hr))
1932 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1934 return hr;
1938 #define GLINFO_LOCATION Adapters[Adapter].gl_info
1939 /* Check if we support bumpmapping for a format */
1940 static BOOL CheckBumpMapCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
1942 if(GL_SUPPORT(NV_REGISTER_COMBINERS) && GL_SUPPORT(NV_TEXTURE_SHADER2)) {
1943 switch (CheckFormat) {
1944 case WINED3DFMT_V8U8:
1945 TRACE_(d3d_caps)("[OK]\n");
1946 return TRUE;
1947 /* TODO: Other bump map formats */
1948 default:
1949 TRACE_(d3d_caps)("[FAILED]\n");
1950 return FALSE;
1953 if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP) || GL_SUPPORT(ATI_FRAGMENT_SHADER)) {
1954 switch (CheckFormat) {
1955 case WINED3DFMT_V8U8:
1956 TRACE_(d3d_caps)("[OK]\n");
1957 return TRUE;
1958 default:
1959 TRACE_(d3d_caps)("[FAILED]\n");
1960 return FALSE;
1963 TRACE_(d3d_caps)("[FAILED]\n");
1964 return FALSE;
1967 /* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
1968 static BOOL CheckDepthStencilCapability(UINT Adapter, WINED3DFORMAT DisplayFormat, WINED3DFORMAT DepthStencilFormat)
1970 int it=0;
1971 WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
1972 const GlPixelFormatDesc *glDesc;
1973 const StaticPixelFormatDesc *desc = getFormatDescEntry(DepthStencilFormat, &GLINFO_LOCATION, &glDesc);
1975 /* Fail if we weren't able to get a description of the format */
1976 if(!desc || !glDesc)
1977 return FALSE;
1979 /* Only allow depth/stencil formats */
1980 if(!(glDesc->Flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
1981 return FALSE;
1983 /* Walk through all WGL pixel formats to find a match */
1984 cfgs = Adapters[Adapter].cfgs;
1985 for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
1986 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], DisplayFormat)) {
1987 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&cfgs[it], DepthStencilFormat)) {
1988 return TRUE;
1993 return FALSE;
1996 static BOOL CheckFilterCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
1998 const GlPixelFormatDesc *glDesc;
1999 const StaticPixelFormatDesc *desc = getFormatDescEntry(CheckFormat, &GLINFO_LOCATION, &glDesc);
2001 /* Fail if we weren't able to get a description of the format */
2002 if(!desc || !glDesc)
2003 return FALSE;
2005 /* The flags entry of a format contains the filtering capability */
2006 if(glDesc->Flags & WINED3DFMT_FLAG_FILTERING)
2007 return TRUE;
2009 return FALSE;
2012 /* Check the render target capabilities of a format */
2013 static BOOL CheckRenderTargetCapability(WINED3DFORMAT AdapterFormat, WINED3DFORMAT CheckFormat)
2015 UINT Adapter = 0;
2016 const GlPixelFormatDesc *glDesc;
2017 const StaticPixelFormatDesc *desc = getFormatDescEntry(CheckFormat, &GLINFO_LOCATION, &glDesc);
2019 /* Fail if we weren't able to get a description of the format */
2020 if(!desc || !glDesc)
2021 return FALSE;
2023 /* Filter out non-RT formats */
2024 if(!(glDesc->Flags & WINED3DFMT_FLAG_RENDERTARGET))
2025 return FALSE;
2027 if(wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) {
2028 WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
2029 int it;
2030 short AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
2031 short CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
2033 getColorBits(AdapterFormat, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
2034 getColorBits(CheckFormat, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
2036 /* In backbuffer mode the front and backbuffer share the same WGL pixelformat.
2037 * The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */
2038 if(!((AdapterRed == CheckRed) && (AdapterGreen == CheckGreen) && (AdapterBlue == CheckBlue))) {
2039 TRACE_(d3d_caps)("[FAILED]\n");
2040 return FALSE;
2043 /* Check if there is a WGL pixel format matching the requirements, the format should also be window
2044 * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
2045 for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
2046 if (cfgs[it].windowDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], CheckFormat)) {
2047 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n", cfgs[it].iPixelFormat, debug_d3dformat(CheckFormat));
2048 return TRUE;
2051 } else if(wined3d_settings.offscreen_rendering_mode == ORM_PBUFFER) {
2052 /* We can probably use this function in FBO mode too on some drivers to get some basic indication of the capabilities. */
2053 WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
2054 int it;
2056 /* Check if there is a WGL pixel format matching the requirements, the pixel format should also be usable with pbuffers */
2057 for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
2058 if (cfgs[it].pbufferDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], CheckFormat)) {
2059 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n", cfgs[it].iPixelFormat, debug_d3dformat(CheckFormat));
2060 return TRUE;
2063 } else if(wined3d_settings.offscreen_rendering_mode == ORM_FBO){
2064 /* For now return TRUE for FBOs until we have some proper checks.
2065 * Note that this function will only be called when the format is around for texturing. */
2066 return TRUE;
2068 return FALSE;
2071 static BOOL CheckSrgbReadCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2073 /* Check for supported sRGB formats (Texture loading and framebuffer) */
2074 if(!GL_SUPPORT(EXT_TEXTURE_SRGB)) {
2075 TRACE_(d3d_caps)("[FAILED] GL_EXT_texture_sRGB not supported\n");
2076 return FALSE;
2079 switch (CheckFormat) {
2080 case WINED3DFMT_A8R8G8B8:
2081 case WINED3DFMT_X8R8G8B8:
2082 case WINED3DFMT_A4R4G4B4:
2083 case WINED3DFMT_L8:
2084 case WINED3DFMT_A8L8:
2085 case WINED3DFMT_DXT1:
2086 case WINED3DFMT_DXT2:
2087 case WINED3DFMT_DXT3:
2088 case WINED3DFMT_DXT4:
2089 case WINED3DFMT_DXT5:
2090 TRACE_(d3d_caps)("[OK]\n");
2091 return TRUE;
2093 default:
2094 TRACE_(d3d_caps)("[FAILED] Gamma texture format %s not supported.\n", debug_d3dformat(CheckFormat));
2095 return FALSE;
2097 return FALSE;
2100 static BOOL CheckSrgbWriteCapability(UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT CheckFormat)
2102 /* Only offer SRGB writing on X8R8G8B8/A8R8G8B8 when we use ARB or GLSL shaders as we are
2103 * doing the color fixup in shaders.
2104 * Note Windows drivers (at least on the Geforce 8800) also offer this on R5G6B5. */
2105 if((CheckFormat == WINED3DFMT_X8R8G8B8) || (CheckFormat == WINED3DFMT_A8R8G8B8)) {
2106 int vs_selected_mode;
2107 int ps_selected_mode;
2108 select_shader_mode(&GLINFO_LOCATION, DeviceType, &ps_selected_mode, &vs_selected_mode);
2110 if((ps_selected_mode == SHADER_ARB) || (ps_selected_mode == SHADER_GLSL)) {
2111 TRACE_(d3d_caps)("[OK]\n");
2112 return TRUE;
2116 TRACE_(d3d_caps)("[FAILED] - no SRGB writing support on format=%s\n", debug_d3dformat(CheckFormat));
2117 return FALSE;
2120 /* Check if a format support blending in combination with pixel shaders */
2121 static BOOL CheckPostPixelShaderBlendingCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2123 const GlPixelFormatDesc *glDesc;
2124 const StaticPixelFormatDesc *desc = getFormatDescEntry(CheckFormat, &GLINFO_LOCATION, &glDesc);
2126 /* Fail if we weren't able to get a description of the format */
2127 if(!desc || !glDesc)
2128 return FALSE;
2130 /* The flags entry of a format contains the post pixel shader blending capability */
2131 if(glDesc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)
2132 return TRUE;
2134 return FALSE;
2137 static BOOL CheckWrapAndMipCapability(UINT Adapter, WINED3DFORMAT CheckFormat) {
2138 /* OpenGL supports mipmapping on all formats basically. Wrapping is unsupported,
2139 * but we have to report mipmapping so we cannot reject this flag. Tests show that
2140 * windows reports WRAPANDMIP on unfilterable surfaces as well, apparently to show
2141 * that wrapping is supported. The lack of filtering will sort out the mipmapping
2142 * capability anyway.
2144 * For now lets report this on all formats, but in the future we may want to
2145 * restrict it to some should games need that
2147 return TRUE;
2150 /* Check if a texture format is supported on the given adapter */
2151 static BOOL CheckTextureCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2153 switch (CheckFormat) {
2155 /*****
2156 * supported: RGB(A) formats
2158 case WINED3DFMT_R8G8B8: /* Enable for dx7, blacklisted for 8 and 9 above */
2159 case WINED3DFMT_A8R8G8B8:
2160 case WINED3DFMT_X8R8G8B8:
2161 case WINED3DFMT_R5G6B5:
2162 case WINED3DFMT_X1R5G5B5:
2163 case WINED3DFMT_A1R5G5B5:
2164 case WINED3DFMT_A4R4G4B4:
2165 case WINED3DFMT_R3G3B2:
2166 case WINED3DFMT_A8:
2167 case WINED3DFMT_X4R4G4B4:
2168 case WINED3DFMT_A8B8G8R8:
2169 case WINED3DFMT_X8B8G8R8:
2170 case WINED3DFMT_A2R10G10B10:
2171 case WINED3DFMT_A2B10G10R10:
2172 case WINED3DFMT_G16R16:
2173 TRACE_(d3d_caps)("[OK]\n");
2174 return TRUE;
2176 /*****
2177 * supported: Palettized
2179 case WINED3DFMT_P8:
2180 TRACE_(d3d_caps)("[OK]\n");
2181 return TRUE;
2182 /* No Windows driver offers A8P8, so don't offer it either */
2183 case WINED3DFMT_A8P8:
2184 return FALSE;
2186 /*****
2187 * Supported: (Alpha)-Luminance
2189 case WINED3DFMT_L8:
2190 case WINED3DFMT_A8L8:
2191 case WINED3DFMT_A4L4:
2192 case WINED3DFMT_L16:
2193 TRACE_(d3d_caps)("[OK]\n");
2194 return TRUE;
2196 /* Depth/stencil is handled using checkDepthStencilCapability, return FALSE here */
2197 case WINED3DFMT_D16_LOCKABLE:
2198 case WINED3DFMT_D16:
2199 case WINED3DFMT_D15S1:
2200 case WINED3DFMT_D24X8:
2201 case WINED3DFMT_D24X4S4:
2202 case WINED3DFMT_D24S8:
2203 case WINED3DFMT_D24FS8:
2204 case WINED3DFMT_D32:
2205 case WINED3DFMT_D32F_LOCKABLE:
2206 return FALSE;
2208 /*****
2209 * Not supported everywhere(depends on GL_ATI_envmap_bumpmap or
2210 * GL_NV_texture_shader), but advertized to make apps happy.
2211 * Enable some because games often fail when they are not available
2212 * and are still playable even without bump mapping
2214 case WINED3DFMT_V8U8:
2215 if(GL_SUPPORT(NV_TEXTURE_SHADER) || GL_SUPPORT(ATI_ENVMAP_BUMPMAP) ||
2216 GL_SUPPORT(ATI_FRAGMENT_SHADER)) {
2217 return TRUE;
2219 if(GL_SUPPORT(ARB_FRAGMENT_SHADER) || GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
2220 /* Shader emulated */
2221 return TRUE;
2223 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2224 return FALSE;
2226 case WINED3DFMT_X8L8V8U8:
2227 case WINED3DFMT_L6V5U5:
2228 if(GL_SUPPORT(ARB_FRAGMENT_SHADER) || GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
2229 /* Shader emulated */
2230 return TRUE;
2232 WARN_(d3d_caps)("[FAILED]\n");
2233 return FALSE;
2235 case WINED3DFMT_Q8W8V8U8:
2236 case WINED3DFMT_V16U16:
2237 if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
2238 WARN_(d3d_caps)("[Not supported, but pretended to do]\n");
2239 return TRUE;
2241 if(GL_SUPPORT(ARB_FRAGMENT_SHADER) || GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
2242 /* Shader emulated */
2243 return TRUE;
2245 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2246 return FALSE;
2248 /* Those are not advertized by the nvidia windows driver, and not
2249 * supported natively by GL_NV_texture_shader or GL_ATI_envmap_bumpmap.
2250 * WINED3DFMT_A2W10V10U10 could be loaded into shaders using the unsigned
2251 * ARGB format if needed
2253 case WINED3DFMT_W11V11U10:
2254 case WINED3DFMT_A2W10V10U10:
2255 WARN_(d3d_caps)("[FAILED]\n");
2256 return FALSE;
2258 case WINED3DFMT_DXT1:
2259 case WINED3DFMT_DXT2:
2260 case WINED3DFMT_DXT3:
2261 case WINED3DFMT_DXT4:
2262 case WINED3DFMT_DXT5:
2263 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
2264 TRACE_(d3d_caps)("[OK]\n");
2265 return TRUE;
2267 TRACE_(d3d_caps)("[FAILED]\n");
2268 return FALSE;
2271 /*****
2272 * Odd formats - not supported
2274 case WINED3DFMT_VERTEXDATA:
2275 case WINED3DFMT_INDEX16:
2276 case WINED3DFMT_INDEX32:
2277 case WINED3DFMT_Q16W16V16U16:
2278 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2279 return FALSE;
2281 /*****
2282 * WINED3DFMT_CxV8U8: Not supported right now
2284 case WINED3DFMT_CxV8U8:
2285 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2286 return FALSE;
2288 /* YUV formats, not supported for now */
2289 case WINED3DFMT_UYVY:
2290 case WINED3DFMT_YUY2:
2291 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2292 return FALSE;
2294 /* Not supported */
2295 case WINED3DFMT_A16B16G16R16:
2296 case WINED3DFMT_A8R3G3B2:
2297 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2298 return FALSE;
2300 /* Floating point formats */
2301 case WINED3DFMT_R16F:
2302 case WINED3DFMT_A16B16G16R16F:
2303 if(GL_SUPPORT(ARB_HALF_FLOAT_PIXEL)) {
2304 TRACE_(d3d_caps)("[OK]\n");
2305 return TRUE;
2307 TRACE_(d3d_caps)("[FAILED]\n");
2308 return FALSE;
2310 case WINED3DFMT_R32F:
2311 case WINED3DFMT_A32B32G32R32F:
2312 if (GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2313 TRACE_(d3d_caps)("[OK]\n");
2314 return TRUE;
2316 TRACE_(d3d_caps)("[FAILED]\n");
2317 return FALSE;
2319 case WINED3DFMT_G16R16F:
2320 case WINED3DFMT_G32R32F:
2321 TRACE_(d3d_caps)("[FAILED]\n");
2322 return FALSE;
2324 /* ATI instancing hack: Although ATI cards do not support Shader Model 3.0, they support
2325 * instancing. To query if the card supports instancing CheckDeviceFormat with the special format
2326 * MAKEFOURCC('I','N','S','T') is used. Should a (broken) app check for this provide a proper return value.
2327 * We can do instancing with all shader versions, but we need vertex shaders.
2329 * Additionally applications have to set the D3DRS_POINTSIZE render state to MAKEFOURCC('I','N','S','T') once
2330 * to enable instancing. WineD3D doesn't need that and just ignores it.
2332 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows.
2334 case WINEMAKEFOURCC('I','N','S','T'):
2335 TRACE("ATI Instancing check hack\n");
2336 if(GL_SUPPORT(ARB_VERTEX_PROGRAM) || GL_SUPPORT(ARB_VERTEX_SHADER)) {
2337 TRACE_(d3d_caps)("[OK]\n");
2338 return TRUE;
2340 TRACE_(d3d_caps)("[FAILED]\n");
2341 return FALSE;
2343 /* Some weird FOURCC formats */
2344 case WINED3DFMT_R8G8_B8G8:
2345 case WINED3DFMT_G8R8_G8B8:
2346 case WINED3DFMT_MULTI2_ARGB8:
2347 TRACE_(d3d_caps)("[FAILED]\n");
2348 return FALSE;
2350 case WINED3DFMT_UNKNOWN:
2351 return FALSE;
2353 default:
2354 ERR("Unhandled format=%s\n", debug_d3dformat(CheckFormat));
2355 break;
2357 return FALSE;
2360 static BOOL CheckVertexTextureCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2362 if (!GL_LIMITS(vertex_samplers)) {
2363 TRACE_(d3d_caps)("[FAILED]\n");
2364 return FALSE;
2367 switch (CheckFormat) {
2368 case WINED3DFMT_A32B32G32R32F:
2369 if (!GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2370 TRACE_(d3d_caps)("[FAILED]\n");
2371 return FALSE;
2373 TRACE_(d3d_caps)("[OK]\n");
2374 return TRUE;
2376 default:
2377 TRACE_(d3d_caps)("[FAILED]\n");
2378 return FALSE;
2380 return FALSE;
2383 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2384 WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat) {
2385 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2386 DWORD UsageCaps = 0;
2388 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%u,%s,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s))\n",
2389 This,
2390 Adapter,
2391 DeviceType, debug_d3ddevicetype(DeviceType),
2392 AdapterFormat, debug_d3dformat(AdapterFormat),
2393 Usage, debug_d3dusage(Usage), debug_d3dusagequery(Usage),
2394 RType, debug_d3dresourcetype(RType),
2395 CheckFormat, debug_d3dformat(CheckFormat));
2397 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2398 return WINED3DERR_INVALIDCALL;
2401 if(RType == WINED3DRTYPE_CUBETEXTURE) {
2402 /* Cubetexture allows:
2403 * - D3DUSAGE_AUTOGENMIPMAP
2404 * - D3DUSAGE_DEPTHSTENCIL
2405 * - D3DUSAGE_DYNAMIC
2406 * - D3DUSAGE_NONSECURE (d3d9ex)
2407 * - D3DUSAGE_RENDERTARGET
2408 * - D3DUSAGE_SOFTWAREPROCESSING
2409 * - D3DUSAGE_QUERY_WRAPANDMIP
2411 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2412 /* Check if the texture format is around */
2413 if(CheckTextureCapability(Adapter, CheckFormat)) {
2414 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
2415 /* Check for automatic mipmap generation support */
2416 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2417 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
2418 } else {
2419 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUTOGEN instead of D3D_OK */
2420 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
2424 /* Always report dynamic locking */
2425 if(Usage & WINED3DUSAGE_DYNAMIC)
2426 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2428 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2429 if(CheckRenderTargetCapability(AdapterFormat, CheckFormat)) {
2430 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2431 } else {
2432 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2433 return WINED3DERR_NOTAVAILABLE;
2437 /* Always report software processing */
2438 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2439 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2441 /* Check QUERY_FILTER support */
2442 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2443 if(CheckFilterCapability(Adapter, CheckFormat)) {
2444 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2445 } else {
2446 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2447 return WINED3DERR_NOTAVAILABLE;
2451 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2452 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2453 if(CheckPostPixelShaderBlendingCapability(Adapter, CheckFormat)) {
2454 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2455 } else {
2456 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2457 return WINED3DERR_NOTAVAILABLE;
2461 /* Check QUERY_SRGBREAD support */
2462 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2463 if(CheckSrgbReadCapability(Adapter, CheckFormat)) {
2464 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2465 } else {
2466 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2467 return WINED3DERR_NOTAVAILABLE;
2471 /* Check QUERY_SRGBWRITE support */
2472 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2473 if(CheckSrgbWriteCapability(Adapter, DeviceType, CheckFormat)) {
2474 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2475 } else {
2476 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2477 return WINED3DERR_NOTAVAILABLE;
2481 /* Check QUERY_VERTEXTEXTURE support */
2482 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2483 if(CheckVertexTextureCapability(Adapter, CheckFormat)) {
2484 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2485 } else {
2486 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2487 return WINED3DERR_NOTAVAILABLE;
2491 /* Check QUERY_WRAPANDMIP support */
2492 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
2493 if(CheckWrapAndMipCapability(Adapter, CheckFormat)) {
2494 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
2495 } else {
2496 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
2497 return WINED3DERR_NOTAVAILABLE;
2500 } else {
2501 TRACE_(d3d_caps)("[FAILED] - Cube texture format not supported\n");
2502 return WINED3DERR_NOTAVAILABLE;
2504 } else {
2505 TRACE_(d3d_caps)("[FAILED] - No cube texture support\n");
2506 return WINED3DERR_NOTAVAILABLE;
2508 } else if(RType == WINED3DRTYPE_SURFACE) {
2509 /* Surface allows:
2510 * - D3DUSAGE_DEPTHSTENCIL
2511 * - D3DUSAGE_NONSECURE (d3d9ex)
2512 * - D3DUSAGE_RENDERTARGET
2515 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
2516 if(CheckDepthStencilCapability(Adapter, AdapterFormat, CheckFormat)) {
2517 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
2518 } else {
2519 TRACE_(d3d_caps)("[FAILED] - No depthstencil support\n");
2520 return WINED3DERR_NOTAVAILABLE;
2524 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2525 if(CheckRenderTargetCapability(AdapterFormat, CheckFormat)) {
2526 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2527 } else {
2528 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2529 return WINED3DERR_NOTAVAILABLE;
2533 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2534 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2535 if(CheckPostPixelShaderBlendingCapability(Adapter, CheckFormat)) {
2536 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2537 } else {
2538 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2539 return WINED3DERR_NOTAVAILABLE;
2542 } else if(RType == WINED3DRTYPE_TEXTURE) {
2543 /* Texture allows:
2544 * - D3DUSAGE_AUTOGENMIPMAP
2545 * - D3DUSAGE_DEPTHSTENCIL
2546 * - D3DUSAGE_DMAP
2547 * - D3DUSAGE_DYNAMIC
2548 * - D3DUSAGE_NONSECURE (d3d9ex)
2549 * - D3DUSAGE_RENDERTARGET
2550 * - D3DUSAGE_SOFTWAREPROCESSING
2551 * - D3DUSAGE_TEXTAPI (d3d9ex)
2552 * - D3DUSAGE_QUERY_WRAPANDMIP
2555 /* Check if the texture format is around */
2556 if(CheckTextureCapability(Adapter, CheckFormat)) {
2557 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
2558 /* Check for automatic mipmap generation support */
2559 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2560 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
2561 } else {
2562 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUTOGEN instead of D3D_OK */
2563 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
2567 /* Always report dynamic locking */
2568 if(Usage & WINED3DUSAGE_DYNAMIC)
2569 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2571 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2572 if(CheckRenderTargetCapability(AdapterFormat, CheckFormat)) {
2573 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2574 } else {
2575 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2576 return WINED3DERR_NOTAVAILABLE;
2580 /* Always report software processing */
2581 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2582 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2584 /* Check QUERY_FILTER support */
2585 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2586 if(CheckFilterCapability(Adapter, CheckFormat)) {
2587 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2588 } else {
2589 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2590 return WINED3DERR_NOTAVAILABLE;
2594 /* Check QUERY_LEGACYBUMPMAP support */
2595 if(Usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP) {
2596 if(CheckBumpMapCapability(Adapter, CheckFormat)) {
2597 UsageCaps |= WINED3DUSAGE_QUERY_LEGACYBUMPMAP;
2598 } else {
2599 TRACE_(d3d_caps)("[FAILED] - No legacy bumpmap support\n");
2600 return WINED3DERR_NOTAVAILABLE;
2604 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2605 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2606 if(CheckPostPixelShaderBlendingCapability(Adapter, CheckFormat)) {
2607 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2608 } else {
2609 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2610 return WINED3DERR_NOTAVAILABLE;
2614 /* Check QUERY_SRGBREAD support */
2615 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2616 if(CheckSrgbReadCapability(Adapter, CheckFormat)) {
2617 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2618 } else {
2619 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2620 return WINED3DERR_NOTAVAILABLE;
2624 /* Check QUERY_SRGBWRITE support */
2625 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2626 if(CheckSrgbWriteCapability(Adapter, DeviceType, CheckFormat)) {
2627 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2628 } else {
2629 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2630 return WINED3DERR_NOTAVAILABLE;
2634 /* Check QUERY_VERTEXTEXTURE support */
2635 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2636 if(CheckVertexTextureCapability(Adapter, CheckFormat)) {
2637 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2638 } else {
2639 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2640 return WINED3DERR_NOTAVAILABLE;
2644 /* Check QUERY_WRAPANDMIP support */
2645 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
2646 if(CheckWrapAndMipCapability(Adapter, CheckFormat)) {
2647 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
2648 } else {
2649 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
2650 return WINED3DERR_NOTAVAILABLE;
2653 } else if(CheckDepthStencilCapability(Adapter, AdapterFormat, CheckFormat)) {
2654 if(Usage & WINED3DUSAGE_DEPTHSTENCIL)
2655 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
2656 } else {
2657 TRACE_(d3d_caps)("[FAILED] - Texture format not supported\n");
2658 return WINED3DERR_NOTAVAILABLE;
2660 } else if((RType == WINED3DRTYPE_VOLUME) || (RType == WINED3DRTYPE_VOLUMETEXTURE)) {
2661 /* Volume is to VolumeTexture what Surface is to Texture but its usage caps are not documented.
2662 * Most driver seem to offer (nearly) the same on Volume and VolumeTexture, so do that too.
2664 * Volumetexture allows:
2665 * - D3DUSAGE_DYNAMIC
2666 * - D3DUSAGE_NONSECURE (d3d9ex)
2667 * - D3DUSAGE_SOFTWAREPROCESSING
2668 * - D3DUSAGE_QUERY_WRAPANDMIP
2671 /* Check volume texture and volume usage caps */
2672 if(GL_SUPPORT(EXT_TEXTURE3D)) {
2673 if(CheckTextureCapability(Adapter, CheckFormat) == FALSE) {
2674 TRACE_(d3d_caps)("[FAILED] - Format not supported\n");
2675 return WINED3DERR_NOTAVAILABLE;
2678 /* Always report dynamic locking */
2679 if(Usage & WINED3DUSAGE_DYNAMIC)
2680 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2682 /* Always report software processing */
2683 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2684 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2686 /* Check QUERY_FILTER support */
2687 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2688 if(CheckFilterCapability(Adapter, CheckFormat)) {
2689 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2690 } else {
2691 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2692 return WINED3DERR_NOTAVAILABLE;
2696 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2697 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2698 if(CheckPostPixelShaderBlendingCapability(Adapter, CheckFormat)) {
2699 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2700 } else {
2701 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2702 return WINED3DERR_NOTAVAILABLE;
2706 /* Check QUERY_SRGBREAD support */
2707 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2708 if(CheckSrgbReadCapability(Adapter, CheckFormat)) {
2709 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2710 } else {
2711 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2712 return WINED3DERR_NOTAVAILABLE;
2716 /* Check QUERY_SRGBWRITE support */
2717 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2718 if(CheckSrgbWriteCapability(Adapter, DeviceType, CheckFormat)) {
2719 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2720 } else {
2721 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2722 return WINED3DERR_NOTAVAILABLE;
2726 /* Check QUERY_VERTEXTEXTURE support */
2727 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2728 if(CheckVertexTextureCapability(Adapter, CheckFormat)) {
2729 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2730 } else {
2731 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2732 return WINED3DERR_NOTAVAILABLE;
2736 /* Check QUERY_WRAPANDMIP support */
2737 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
2738 if(CheckWrapAndMipCapability(Adapter, CheckFormat)) {
2739 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
2740 } else {
2741 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
2742 return WINED3DERR_NOTAVAILABLE;
2745 } else {
2746 TRACE_(d3d_caps)("[FAILED] - No volume texture support\n");
2747 return WINED3DERR_NOTAVAILABLE;
2750 /* Filter formats that need conversion; For one part, this conversion is unimplemented,
2751 * and volume textures are huge, so it would be a big performance hit. Unless we hit an
2752 * app needing one of those formats, don't advertize them to avoid leading apps into
2753 * temptation. The windows drivers don't support most of those formats on volumes anyway,
2754 * except of R32F.
2756 switch(CheckFormat) {
2757 case WINED3DFMT_P8:
2758 case WINED3DFMT_A4L4:
2759 case WINED3DFMT_R32F:
2760 case WINED3DFMT_R16F:
2761 case WINED3DFMT_X8L8V8U8:
2762 case WINED3DFMT_L6V5U5:
2763 case WINED3DFMT_G16R16:
2764 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2765 return WINED3DERR_NOTAVAILABLE;
2767 case WINED3DFMT_Q8W8V8U8:
2768 case WINED3DFMT_V16U16:
2769 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
2770 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2771 return WINED3DERR_NOTAVAILABLE;
2773 break;
2775 case WINED3DFMT_V8U8:
2776 if(!GL_SUPPORT(NV_TEXTURE_SHADER) || !GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
2777 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2778 return WINED3DERR_NOTAVAILABLE;
2780 break;
2782 case WINED3DFMT_DXT1:
2783 case WINED3DFMT_DXT2:
2784 case WINED3DFMT_DXT3:
2785 case WINED3DFMT_DXT4:
2786 case WINED3DFMT_DXT5:
2787 /* The GL_EXT_texture_compression_s3tc spec requires that loading an s3tc
2788 * compressed texture results in an error. While the D3D refrast does
2789 * support s3tc volumes, at least the nvidia windows driver does not, so
2790 * we're free not to support this format.
2792 TRACE_(d3d_caps)("[FAILED] - DXTn does not support 3D textures\n");
2793 return WINED3DERR_NOTAVAILABLE;
2795 default:
2796 /* Do nothing, continue with checking the format below */
2797 break;
2799 } else if((RType == WINED3DRTYPE_INDEXBUFFER) || (RType == WINED3DRTYPE_VERTEXBUFFER)){
2800 /* For instance vertexbuffer/indexbuffer aren't supported yet because no Windows drivers seem to offer it */
2801 TRACE_(d3d_caps)("Unhandled resource type D3DRTYPE_INDEXBUFFER / D3DRTYPE_VERTEXBUFFER\n");
2802 return WINED3DERR_NOTAVAILABLE;
2805 /* This format is nothing special and it is supported perfectly.
2806 * However, ati and nvidia driver on windows do not mark this format as
2807 * supported (tested with the dxCapsViewer) and pretending to
2808 * support this format uncovers a bug in Battlefield 1942 (fonts are missing)
2809 * So do the same as Windows drivers and pretend not to support it on dx8 and 9
2810 * Enable it on dx7. It will need additional checking on dx10 when we support it.
2812 if(This->dxVersion > 7 && CheckFormat == WINED3DFMT_R8G8B8) {
2813 TRACE_(d3d_caps)("[FAILED]\n");
2814 return WINED3DERR_NOTAVAILABLE;
2817 /* When the UsageCaps exactly matches Usage return WINED3D_OK except for the situation in which
2818 * WINED3DUSAGE_AUTOGENMIPMAP isn't around, then WINED3DOK_NOAUTOGEN is returned if all the other
2819 * usage flags match. */
2820 if(UsageCaps == Usage) {
2821 return WINED3D_OK;
2822 } else if((UsageCaps == (Usage & ~WINED3DUSAGE_AUTOGENMIPMAP)) && (Usage & WINED3DUSAGE_AUTOGENMIPMAP)){
2823 return WINED3DOK_NOAUTOGEN;
2824 } else {
2825 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);
2826 return WINED3DERR_NOTAVAILABLE;
2830 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2831 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
2832 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2834 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))\n",
2835 This,
2836 Adapter,
2837 DeviceType, debug_d3ddevicetype(DeviceType),
2838 SourceFormat, debug_d3dformat(SourceFormat),
2839 TargetFormat, debug_d3dformat(TargetFormat));
2840 return WINED3D_OK;
2843 static const shader_backend_t *select_shader_backend(UINT Adapter, WINED3DDEVTYPE DeviceType) {
2844 const shader_backend_t *ret;
2845 int vs_selected_mode;
2846 int ps_selected_mode;
2848 select_shader_mode(&GLINFO_LOCATION, DeviceType, &ps_selected_mode, &vs_selected_mode);
2849 if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) {
2850 ret = &glsl_shader_backend;
2851 } else if (vs_selected_mode == SHADER_ARB && ps_selected_mode != SHADER_NONE &&
2852 !GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
2853 ret = &atifs_shader_backend;
2854 } else if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) {
2855 ret = &arb_program_shader_backend;
2856 } else {
2857 ret = &none_shader_backend;
2859 return ret;
2862 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
2863 subset of a D3DCAPS9 structure. However, it has to come via a void *
2864 as the d3d8 interface cannot import the d3d9 header */
2865 static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
2867 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2868 int vs_selected_mode;
2869 int ps_selected_mode;
2870 struct shader_caps shader_caps;
2871 const shader_backend_t *shader_backend;
2873 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
2875 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2876 return WINED3DERR_INVALIDCALL;
2879 select_shader_mode(&Adapters[Adapter].gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
2881 /* This function should *not* be modifying GL caps
2882 * TODO: move the functionality where it belongs */
2883 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &Adapters[Adapter].gl_info);
2885 /* ------------------------------------------------
2886 The following fields apply to both d3d8 and d3d9
2887 ------------------------------------------------ */
2888 pCaps->DeviceType = (DeviceType == WINED3DDEVTYPE_HAL) ? WINED3DDEVTYPE_HAL : WINED3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
2889 pCaps->AdapterOrdinal = Adapter;
2891 pCaps->Caps = 0;
2892 pCaps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
2893 WINED3DCAPS2_FULLSCREENGAMMA |
2894 WINED3DCAPS2_DYNAMICTEXTURES;
2895 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2896 pCaps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
2898 pCaps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD;
2899 pCaps->PresentationIntervals = WINED3DPRESENT_INTERVAL_IMMEDIATE |
2900 WINED3DPRESENT_INTERVAL_ONE;
2902 pCaps->CursorCaps = WINED3DCURSORCAPS_COLOR |
2903 WINED3DCURSORCAPS_LOWRES;
2905 pCaps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
2906 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
2907 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
2908 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
2909 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
2910 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
2911 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
2912 WINED3DDEVCAPS_PUREDEVICE |
2913 WINED3DDEVCAPS_HWRASTERIZATION |
2914 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
2915 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
2916 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
2917 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
2918 WINED3DDEVCAPS_DRAWPRIMITIVES2EX |
2919 WINED3DDEVCAPS_RTPATCHES;
2921 pCaps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
2922 WINED3DPMISCCAPS_CULLCCW |
2923 WINED3DPMISCCAPS_CULLCW |
2924 WINED3DPMISCCAPS_COLORWRITEENABLE |
2925 WINED3DPMISCCAPS_CLIPTLVERTS |
2926 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
2927 WINED3DPMISCCAPS_MASKZ |
2928 WINED3DPMISCCAPS_BLENDOP;
2929 /* TODO:
2930 WINED3DPMISCCAPS_NULLREFERENCE
2931 WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS
2932 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
2933 WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
2934 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING
2935 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
2937 if(GL_SUPPORT(EXT_BLEND_EQUATION_SEPARATE) && GL_SUPPORT(EXT_BLEND_FUNC_SEPARATE))
2938 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
2940 pCaps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
2941 WINED3DPRASTERCAPS_PAT |
2942 WINED3DPRASTERCAPS_WFOG |
2943 WINED3DPRASTERCAPS_ZFOG |
2944 WINED3DPRASTERCAPS_FOGVERTEX |
2945 WINED3DPRASTERCAPS_FOGTABLE |
2946 WINED3DPRASTERCAPS_STIPPLE |
2947 WINED3DPRASTERCAPS_SUBPIXEL |
2948 WINED3DPRASTERCAPS_ZTEST |
2949 WINED3DPRASTERCAPS_SCISSORTEST |
2950 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
2951 WINED3DPRASTERCAPS_DEPTHBIAS;
2953 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2954 pCaps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY |
2955 WINED3DPRASTERCAPS_ZBIAS |
2956 WINED3DPRASTERCAPS_MIPMAPLODBIAS;
2958 if(GL_SUPPORT(NV_FOG_DISTANCE)) {
2959 pCaps->RasterCaps |= WINED3DPRASTERCAPS_FOGRANGE;
2961 /* FIXME Add:
2962 WINED3DPRASTERCAPS_COLORPERSPECTIVE
2963 WINED3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
2964 WINED3DPRASTERCAPS_ANTIALIASEDGES
2965 WINED3DPRASTERCAPS_ZBUFFERLESSHSR
2966 WINED3DPRASTERCAPS_WBUFFER */
2968 pCaps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
2969 WINED3DPCMPCAPS_EQUAL |
2970 WINED3DPCMPCAPS_GREATER |
2971 WINED3DPCMPCAPS_GREATEREQUAL |
2972 WINED3DPCMPCAPS_LESS |
2973 WINED3DPCMPCAPS_LESSEQUAL |
2974 WINED3DPCMPCAPS_NEVER |
2975 WINED3DPCMPCAPS_NOTEQUAL;
2977 pCaps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
2978 WINED3DPBLENDCAPS_BOTHSRCALPHA |
2979 WINED3DPBLENDCAPS_DESTALPHA |
2980 WINED3DPBLENDCAPS_DESTCOLOR |
2981 WINED3DPBLENDCAPS_INVDESTALPHA |
2982 WINED3DPBLENDCAPS_INVDESTCOLOR |
2983 WINED3DPBLENDCAPS_INVSRCALPHA |
2984 WINED3DPBLENDCAPS_INVSRCCOLOR |
2985 WINED3DPBLENDCAPS_ONE |
2986 WINED3DPBLENDCAPS_SRCALPHA |
2987 WINED3DPBLENDCAPS_SRCALPHASAT |
2988 WINED3DPBLENDCAPS_SRCCOLOR |
2989 WINED3DPBLENDCAPS_ZERO;
2991 pCaps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
2992 WINED3DPBLENDCAPS_DESTCOLOR |
2993 WINED3DPBLENDCAPS_INVDESTALPHA |
2994 WINED3DPBLENDCAPS_INVDESTCOLOR |
2995 WINED3DPBLENDCAPS_INVSRCALPHA |
2996 WINED3DPBLENDCAPS_INVSRCCOLOR |
2997 WINED3DPBLENDCAPS_ONE |
2998 WINED3DPBLENDCAPS_SRCALPHA |
2999 WINED3DPBLENDCAPS_SRCCOLOR |
3000 WINED3DPBLENDCAPS_ZERO;
3001 /* NOTE: WINED3DPBLENDCAPS_SRCALPHASAT is not supported as dest blend factor,
3002 * according to the glBlendFunc manpage
3004 * WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA are
3005 * legacy settings for srcblend only
3008 if( GL_SUPPORT(EXT_BLEND_COLOR)) {
3009 pCaps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
3010 pCaps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
3014 pCaps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
3015 WINED3DPCMPCAPS_EQUAL |
3016 WINED3DPCMPCAPS_GREATER |
3017 WINED3DPCMPCAPS_GREATEREQUAL |
3018 WINED3DPCMPCAPS_LESS |
3019 WINED3DPCMPCAPS_LESSEQUAL |
3020 WINED3DPCMPCAPS_NEVER |
3021 WINED3DPCMPCAPS_NOTEQUAL;
3023 pCaps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
3024 WINED3DPSHADECAPS_COLORGOURAUDRGB |
3025 WINED3DPSHADECAPS_ALPHAFLATBLEND |
3026 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
3027 WINED3DPSHADECAPS_COLORFLATRGB |
3028 WINED3DPSHADECAPS_FOGFLAT |
3029 WINED3DPSHADECAPS_FOGGOURAUD |
3030 WINED3DPSHADECAPS_SPECULARFLATRGB;
3032 pCaps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
3033 WINED3DPTEXTURECAPS_ALPHAPALETTE |
3034 WINED3DPTEXTURECAPS_BORDER |
3035 WINED3DPTEXTURECAPS_MIPMAP |
3036 WINED3DPTEXTURECAPS_PROJECTED |
3037 WINED3DPTEXTURECAPS_PERSPECTIVE;
3039 if( !GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
3040 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
3041 WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
3044 if( GL_SUPPORT(EXT_TEXTURE3D)) {
3045 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP |
3046 WINED3DPTEXTURECAPS_MIPVOLUMEMAP |
3047 WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
3050 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
3051 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP |
3052 WINED3DPTEXTURECAPS_MIPCUBEMAP |
3053 WINED3DPTEXTURECAPS_CUBEMAP_POW2;
3057 pCaps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3058 WINED3DPTFILTERCAPS_MAGFPOINT |
3059 WINED3DPTFILTERCAPS_MINFLINEAR |
3060 WINED3DPTFILTERCAPS_MINFPOINT |
3061 WINED3DPTFILTERCAPS_MIPFLINEAR |
3062 WINED3DPTFILTERCAPS_MIPFPOINT |
3063 WINED3DPTFILTERCAPS_LINEAR |
3064 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3065 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3066 WINED3DPTFILTERCAPS_MIPLINEAR |
3067 WINED3DPTFILTERCAPS_MIPNEAREST |
3068 WINED3DPTFILTERCAPS_NEAREST;
3070 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3071 pCaps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
3072 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
3075 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
3076 pCaps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3077 WINED3DPTFILTERCAPS_MAGFPOINT |
3078 WINED3DPTFILTERCAPS_MINFLINEAR |
3079 WINED3DPTFILTERCAPS_MINFPOINT |
3080 WINED3DPTFILTERCAPS_MIPFLINEAR |
3081 WINED3DPTFILTERCAPS_MIPFPOINT |
3082 WINED3DPTFILTERCAPS_LINEAR |
3083 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3084 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3085 WINED3DPTFILTERCAPS_MIPLINEAR |
3086 WINED3DPTFILTERCAPS_MIPNEAREST |
3087 WINED3DPTFILTERCAPS_NEAREST;
3089 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3090 pCaps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
3091 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
3093 } else
3094 pCaps->CubeTextureFilterCaps = 0;
3096 if (GL_SUPPORT(EXT_TEXTURE3D)) {
3097 pCaps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3098 WINED3DPTFILTERCAPS_MAGFPOINT |
3099 WINED3DPTFILTERCAPS_MINFLINEAR |
3100 WINED3DPTFILTERCAPS_MINFPOINT |
3101 WINED3DPTFILTERCAPS_MIPFLINEAR |
3102 WINED3DPTFILTERCAPS_MIPFPOINT |
3103 WINED3DPTFILTERCAPS_LINEAR |
3104 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3105 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3106 WINED3DPTFILTERCAPS_MIPLINEAR |
3107 WINED3DPTFILTERCAPS_MIPNEAREST |
3108 WINED3DPTFILTERCAPS_NEAREST;
3109 } else
3110 pCaps->VolumeTextureFilterCaps = 0;
3112 pCaps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
3113 WINED3DPTADDRESSCAPS_CLAMP |
3114 WINED3DPTADDRESSCAPS_WRAP;
3116 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
3117 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
3119 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
3120 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
3122 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
3123 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
3126 if (GL_SUPPORT(EXT_TEXTURE3D)) {
3127 pCaps->VolumeTextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
3128 WINED3DPTADDRESSCAPS_CLAMP |
3129 WINED3DPTADDRESSCAPS_WRAP;
3130 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
3131 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
3133 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
3134 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
3136 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
3137 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
3139 } else
3140 pCaps->VolumeTextureAddressCaps = 0;
3142 pCaps->LineCaps = WINED3DLINECAPS_TEXTURE |
3143 WINED3DLINECAPS_ZTEST;
3144 /* FIXME: Add
3145 WINED3DLINECAPS_BLEND
3146 WINED3DLINECAPS_ALPHACMP
3147 WINED3DLINECAPS_FOG */
3149 pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
3150 pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
3152 if(GL_SUPPORT(EXT_TEXTURE3D))
3153 pCaps->MaxVolumeExtent = GL_LIMITS(texture3d_size);
3154 else
3155 pCaps->MaxVolumeExtent = 0;
3157 pCaps->MaxTextureRepeat = 32768;
3158 pCaps->MaxTextureAspectRatio = GL_LIMITS(texture_size);
3159 pCaps->MaxVertexW = 1.0;
3161 pCaps->GuardBandLeft = 0;
3162 pCaps->GuardBandTop = 0;
3163 pCaps->GuardBandRight = 0;
3164 pCaps->GuardBandBottom = 0;
3166 pCaps->ExtentsAdjust = 0;
3168 pCaps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
3169 WINED3DSTENCILCAPS_INCRSAT |
3170 WINED3DSTENCILCAPS_INVERT |
3171 WINED3DSTENCILCAPS_KEEP |
3172 WINED3DSTENCILCAPS_REPLACE |
3173 WINED3DSTENCILCAPS_ZERO;
3174 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
3175 pCaps->StencilCaps |= WINED3DSTENCILCAPS_DECR |
3176 WINED3DSTENCILCAPS_INCR;
3178 if ( This->dxVersion > 8 &&
3179 ( GL_SUPPORT(EXT_STENCIL_TWO_SIDE) ||
3180 GL_SUPPORT(ATI_SEPARATE_STENCIL) ) ) {
3181 pCaps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
3184 pCaps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
3186 pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
3187 pCaps->MaxActiveLights = GL_LIMITS(lights);
3189 pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
3190 pCaps->MaxVertexBlendMatrixIndex = 0;
3192 pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
3193 pCaps->MaxPointSize = GL_LIMITS(pointsize);
3196 pCaps->VertexProcessingCaps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
3197 WINED3DVTXPCAPS_MATERIALSOURCE7 |
3198 WINED3DVTXPCAPS_POSITIONALLIGHTS |
3199 WINED3DVTXPCAPS_LOCALVIEWER |
3200 WINED3DVTXPCAPS_VERTEXFOG |
3201 WINED3DVTXPCAPS_TEXGEN;
3202 /* FIXME: Add
3203 D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
3205 pCaps->MaxPrimitiveCount = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
3206 pCaps->MaxVertexIndex = 0xFFFFF;
3207 pCaps->MaxStreams = MAX_STREAMS;
3208 pCaps->MaxStreamStride = 1024;
3210 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
3211 pCaps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET;
3212 /* TODO: VS3.0 needs at least D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET */
3213 pCaps->MaxNpatchTessellationLevel = 0;
3214 pCaps->MasterAdapterOrdinal = 0;
3215 pCaps->AdapterOrdinalInGroup = 0;
3216 pCaps->NumberOfAdaptersInGroup = 1;
3218 pCaps->NumSimultaneousRTs = GL_LIMITS(buffers);
3220 pCaps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
3221 WINED3DPTFILTERCAPS_MAGFPOINT |
3222 WINED3DPTFILTERCAPS_MINFLINEAR |
3223 WINED3DPTFILTERCAPS_MAGFLINEAR;
3224 pCaps->VertexTextureFilterCaps = 0;
3226 memset(&shader_caps, 0, sizeof(shader_caps));
3227 shader_backend = select_shader_backend(Adapter, DeviceType);
3228 shader_backend->shader_get_caps(DeviceType, &GLINFO_LOCATION, &shader_caps);
3230 /* Add shader misc caps. Only some of them belong to the shader parts of the pipeline */
3231 pCaps->PrimitiveMiscCaps |= shader_caps.PrimitiveMiscCaps;
3233 /* This takes care for disabling vertex shader or pixel shader caps while leaving the other one enabled.
3234 * Ignore shader model capabilities if disabled in config
3236 if(vs_selected_mode == SHADER_NONE) {
3237 TRACE_(d3d_caps)("Vertex shader disabled in config, reporting version 0.0\n");
3238 pCaps->VertexShaderVersion = WINED3DVS_VERSION(0,0);
3239 pCaps->MaxVertexShaderConst = 0;
3240 } else {
3241 pCaps->VertexShaderVersion = shader_caps.VertexShaderVersion;
3242 pCaps->MaxVertexShaderConst = shader_caps.MaxVertexShaderConst;
3245 if(ps_selected_mode == SHADER_NONE) {
3246 TRACE_(d3d_caps)("Pixel shader disabled in config, reporting version 0.0\n");
3247 pCaps->PixelShaderVersion = WINED3DPS_VERSION(0,0);
3248 pCaps->PixelShader1xMaxValue = 0.0;
3249 } else {
3250 pCaps->PixelShaderVersion = shader_caps.PixelShaderVersion;
3251 pCaps->PixelShader1xMaxValue = shader_caps.PixelShader1xMaxValue;
3254 pCaps->TextureOpCaps = shader_caps.TextureOpCaps;
3255 pCaps->MaxTextureBlendStages = shader_caps.MaxTextureBlendStages;
3256 pCaps->MaxSimultaneousTextures = shader_caps.MaxSimultaneousTextures;
3257 pCaps->VS20Caps = shader_caps.VS20Caps;
3258 pCaps->MaxVShaderInstructionsExecuted = shader_caps.MaxVShaderInstructionsExecuted;
3259 pCaps->MaxVertexShader30InstructionSlots= shader_caps.MaxVertexShader30InstructionSlots;
3260 pCaps->PS20Caps = shader_caps.PS20Caps;
3261 pCaps->MaxPShaderInstructionsExecuted = shader_caps.MaxPShaderInstructionsExecuted;
3262 pCaps->MaxPixelShader30InstructionSlots = shader_caps.MaxPixelShader30InstructionSlots;
3264 /* The following caps are shader specific, but they are things we cannot detect, or which
3265 * are the same among all shader models. So to avoid code duplication set the shader version
3266 * specific, but otherwise constant caps here
3268 if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(3,0)) {
3269 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
3270 use the VS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum VS3.0 value. */
3271 pCaps->VS20Caps.Caps = WINED3DVS20CAPS_PREDICATION;
3272 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
3273 pCaps->VS20Caps.NumTemps = max(32, GLINFO_LOCATION.vs_arb_max_temps);
3274 pCaps->VS20Caps.StaticFlowControlDepth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH ; /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
3276 pCaps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
3277 pCaps->MaxVertexShader30InstructionSlots = max(512, GLINFO_LOCATION.vs_arb_max_instructions);
3278 } else if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(2,0)) {
3279 pCaps->VS20Caps.Caps = 0;
3280 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
3281 pCaps->VS20Caps.NumTemps = max(12, GLINFO_LOCATION.vs_arb_max_temps);
3282 pCaps->VS20Caps.StaticFlowControlDepth = 1;
3284 pCaps->MaxVShaderInstructionsExecuted = 65535;
3285 pCaps->MaxVertexShader30InstructionSlots = 0;
3286 } else { /* VS 1.x */
3287 pCaps->VS20Caps.Caps = 0;
3288 pCaps->VS20Caps.DynamicFlowControlDepth = 0;
3289 pCaps->VS20Caps.NumTemps = 0;
3290 pCaps->VS20Caps.StaticFlowControlDepth = 0;
3292 pCaps->MaxVShaderInstructionsExecuted = 0;
3293 pCaps->MaxVertexShader30InstructionSlots = 0;
3296 if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(3,0)) {
3297 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
3298 use the PS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum PS 3.0 value. */
3300 /* 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 */
3301 pCaps->PS20Caps.Caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
3302 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
3303 WINED3DPS20CAPS_PREDICATION |
3304 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
3305 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
3306 pCaps->PS20Caps.DynamicFlowControlDepth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
3307 pCaps->PS20Caps.NumTemps = max(32, GLINFO_LOCATION.ps_arb_max_temps);
3308 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
3309 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
3311 pCaps->MaxPShaderInstructionsExecuted = 65535;
3312 pCaps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS, GLINFO_LOCATION.ps_arb_max_instructions);
3313 } else if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(2,0)) {
3314 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
3315 pCaps->PS20Caps.Caps = 0;
3316 pCaps->PS20Caps.DynamicFlowControlDepth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
3317 pCaps->PS20Caps.NumTemps = max(12, GLINFO_LOCATION.ps_arb_max_temps);
3318 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
3319 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
3321 pCaps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
3322 pCaps->MaxPixelShader30InstructionSlots = 0;
3323 } else { /* PS 1.x */
3324 pCaps->PS20Caps.Caps = 0;
3325 pCaps->PS20Caps.DynamicFlowControlDepth = 0;
3326 pCaps->PS20Caps.NumTemps = 0;
3327 pCaps->PS20Caps.StaticFlowControlDepth = 0;
3328 pCaps->PS20Caps.NumInstructionSlots = 0;
3330 pCaps->MaxPShaderInstructionsExecuted = 0;
3331 pCaps->MaxPixelShader30InstructionSlots = 0;
3334 if(pCaps->VertexShaderVersion >= WINED3DVS_VERSION(2,0)) {
3335 /* OpenGL supports all the formats below, perhaps not always
3336 * without conversion, but it supports them.
3337 * Further GLSL doesn't seem to have an official unsigned type so
3338 * don't advertise it yet as I'm not sure how we handle it.
3339 * We might need to add some clamping in the shader engine to
3340 * support it.
3341 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
3342 pCaps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
3343 WINED3DDTCAPS_UBYTE4N |
3344 WINED3DDTCAPS_SHORT2N |
3345 WINED3DDTCAPS_SHORT4N;
3346 if (GL_SUPPORT(NV_HALF_FLOAT)) {
3347 pCaps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
3348 WINED3DDTCAPS_FLOAT16_4;
3350 } else
3351 pCaps->DeclTypes = 0;
3353 return WINED3D_OK;
3356 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
3357 and fields being inserted in the middle, a new structure is used in place */
3358 static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, HWND hFocusWindow,
3359 DWORD BehaviourFlags, IWineD3DDevice** ppReturnedDeviceInterface,
3360 IUnknown *parent) {
3362 IWineD3DDeviceImpl *object = NULL;
3363 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3364 WINED3DDISPLAYMODE mode;
3365 int i;
3367 /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
3368 * number and create a device without a 3D adapter for 2D only operation.
3370 if (IWineD3D_GetAdapterCount(iface) && Adapter >= IWineD3D_GetAdapterCount(iface)) {
3371 return WINED3DERR_INVALIDCALL;
3374 /* Create a WineD3DDevice object */
3375 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
3376 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
3377 TRACE("Created WineD3DDevice object @ %p\n", object);
3378 if (NULL == object) {
3379 return WINED3DERR_OUTOFVIDEOMEMORY;
3382 /* Set up initial COM information */
3383 object->lpVtbl = &IWineD3DDevice_Vtbl;
3384 object->ref = 1;
3385 object->wineD3D = iface;
3386 object->adapter = numAdapters ? &Adapters[Adapter] : NULL;
3387 IWineD3D_AddRef(object->wineD3D);
3388 object->parent = parent;
3389 list_init(&object->resources);
3390 list_init(&object->shaders);
3392 if(This->dxVersion == 7) {
3393 object->surface_alignment = 8;
3394 } else {
3395 object->surface_alignment = 4;
3397 object->posFixup[0] = 1.0; /* This is needed to get the x coord unmodified through a MAD */
3399 /* Set the state up as invalid until the device is fully created */
3400 object->state = WINED3DERR_DRIVERINTERNALERROR;
3402 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %x, RetDevInt: %p)\n", This, Adapter, DeviceType,
3403 hFocusWindow, BehaviourFlags, ppReturnedDeviceInterface);
3405 /* Save the creation parameters */
3406 object->createParms.AdapterOrdinal = Adapter;
3407 object->createParms.DeviceType = DeviceType;
3408 object->createParms.hFocusWindow = hFocusWindow;
3409 object->createParms.BehaviorFlags = BehaviourFlags;
3411 /* Initialize other useful values */
3412 object->adapterNo = Adapter;
3413 object->devType = DeviceType;
3415 select_shader_mode(&GLINFO_LOCATION, DeviceType, &object->ps_selected_mode, &object->vs_selected_mode);
3416 object->shader_backend = select_shader_backend(Adapter, DeviceType);
3418 /* Prefer the vtable with functions optimized for single dirtifyable objects if the shader
3419 * model can deal with that. It is essentially the same, just with adjusted
3420 * Set*ShaderConstantF implementations
3422 if(object->shader_backend->shader_dirtifyable_constants((IWineD3DDevice *) object)) {
3423 object->lpVtbl = &IWineD3DDevice_DirtyConst_Vtbl;
3426 /* set the state of the device to valid */
3427 object->state = WINED3D_OK;
3429 /* Get the initial screen setup for ddraw */
3430 IWineD3DImpl_GetAdapterDisplayMode(iface, Adapter, &mode);
3432 object->ddraw_width = mode.Width;
3433 object->ddraw_height = mode.Height;
3434 object->ddraw_format = mode.Format;
3436 for(i = 0; i < PATCHMAP_SIZE; i++) {
3437 list_init(&object->patches[i]);
3439 return WINED3D_OK;
3441 #undef GLINFO_LOCATION
3443 static HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
3444 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3445 IUnknown_AddRef(This->parent);
3446 *pParent = This->parent;
3447 return WINED3D_OK;
3450 ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface) {
3451 IUnknown* surfaceParent;
3452 TRACE("(%p) call back\n", pSurface);
3454 /* Now, release the parent, which will take care of cleaning up the surface for us */
3455 IWineD3DSurface_GetParent(pSurface, &surfaceParent);
3456 IUnknown_Release(surfaceParent);
3457 return IUnknown_Release(surfaceParent);
3460 ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pVolume) {
3461 IUnknown* volumeParent;
3462 TRACE("(%p) call back\n", pVolume);
3464 /* Now, release the parent, which will take care of cleaning up the volume for us */
3465 IWineD3DVolume_GetParent(pVolume, &volumeParent);
3466 IUnknown_Release(volumeParent);
3467 return IUnknown_Release(volumeParent);
3470 static BOOL implementation_is_apple(WineD3D_GL_Info *gl_info) {
3471 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
3472 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
3473 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
3475 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
3476 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
3477 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
3478 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
3479 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
3480 * the chance that other implementations support them is rather small since Win32 QuickTime uses
3481 * DirectDraw, not OpenGL.
3483 if(gl_info->supported[APPLE_FENCE] &&
3484 gl_info->supported[APPLE_CLIENT_STORAGE] &&
3485 gl_info->supported[APPLE_FLUSH_RENDER] &&
3486 gl_info->supported[APPLE_YCBCR_422]) {
3487 TRACE_(d3d_caps)("GL_APPLE_fence, GL_APPLE_client_storage, GL_APPLE_flush_render and GL_ycbcr_422 are supported\n");
3488 TRACE_(d3d_caps)("Activating MacOS fixups\n");
3489 return TRUE;
3490 } else {
3491 TRACE_(d3d_caps)("Apple extensions are not supported\n");
3492 TRACE_(d3d_caps)("Not activating MacOS fixups\n");
3493 return FALSE;
3497 #define GLINFO_LOCATION (*gl_info)
3498 static void test_pbo_functionality(WineD3D_GL_Info *gl_info) {
3499 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
3500 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
3501 * all the texture. This function detects this bug by its symptom and disables PBOs
3502 * if the test fails.
3504 * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
3505 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
3506 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
3507 * read back is compared to the original. If they are equal PBOs are assumed to work,
3508 * otherwise the PBO extension is disabled.
3510 GLuint texture, pbo;
3511 static const unsigned int pattern[] = {
3512 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
3513 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
3514 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
3515 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
3517 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
3519 if(!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) {
3520 /* No PBO -> No point in testing them */
3521 return;
3524 while(glGetError());
3525 glGenTextures(1, &texture);
3526 glBindTexture(GL_TEXTURE_2D, texture);
3527 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
3528 checkGLcall("Specifying the PBO test texture\n");
3530 GL_EXTCALL(glGenBuffersARB(1, &pbo));
3531 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
3532 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
3533 checkGLcall("Specifying the PBO test pbo\n");
3535 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
3536 checkGLcall("Loading the PBO test texture\n");
3538 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
3539 glFinish(); /* just to be sure */
3541 memset(check, 0, sizeof(check));
3542 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
3543 checkGLcall("Reading back the PBO test texture\n");
3545 glDeleteTextures(1, &texture);
3546 GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
3547 checkGLcall("PBO test cleanup\n");
3549 if(memcmp(check, pattern, sizeof(check)) != 0) {
3550 WARN_(d3d_caps)("PBO test failed, read back data doesn't match original\n");
3551 WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance\n");
3552 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
3553 } else {
3554 TRACE_(d3d_caps)("PBO test successful\n");
3557 #undef GLINFO_LOCATION
3559 /* Certain applications(Steam) complain if we report an outdated driver version. In general,
3560 * reporting a driver version is moot because we are not the Windows driver, and we have different
3561 * bugs, features, etc.
3563 * If a card is not found in this table, the gl driver version is reported
3565 struct driver_version_information {
3566 WORD vendor; /* reported PCI card vendor ID */
3567 WORD card; /* reported PCI card device ID */
3568 WORD hipart_hi, hipart_lo; /* driver hiword to report */
3569 WORD lopart_hi, lopart_lo; /* driver loword to report */
3572 static const struct driver_version_information driver_version_table[] = {
3573 /* Nvidia drivers. Geforce FX and newer cards are supported by the current driver */
3574 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, 7, 15, 10, 16921 },
3575 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, 7, 15, 10, 16921 },
3576 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, 7, 15, 10, 16921 },
3577 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, 7, 15, 10, 16921 },
3578 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, 7, 15, 10, 16921 },
3579 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, 7, 15, 10, 16921 },
3580 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, 7, 15, 10, 16921 },
3581 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, 7, 15, 10, 16921 },
3582 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, 7, 15, 10, 16921 },
3583 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, 7, 15, 10, 16921 },
3584 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, 7, 15, 10, 16921 },
3585 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, 7, 15, 10, 16921 },
3586 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, 7, 15, 10, 16921 },
3587 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, 7, 15, 10, 16921 },
3589 /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode */
3590 {VENDOR_ATI, CARD_ATI_RADEON_9500, 6, 14, 10, 6764 },
3591 {VENDOR_ATI, CARD_ATI_RADEON_X700, 6, 14, 10, 6764 },
3592 {VENDOR_ATI, CARD_ATI_RADEON_X1600, 6, 14, 10, 6764 },
3593 {VENDOR_ATI, CARD_ATI_RADEON_HD2300, 6, 14, 10, 6764 },
3594 {VENDOR_ATI, CARD_ATI_RADEON_HD2600, 6, 14, 10, 6764 },
3595 {VENDOR_ATI, CARD_ATI_RADEON_HD2900, 6, 14, 10, 6764 },
3597 /* TODO: Add information about legacy nvidia and ATI hardware, Intel and other cards */
3600 static void fixup_extensions(WineD3D_GL_Info *gl_info) {
3601 unsigned int i;
3602 BOOL apple = implementation_is_apple(gl_info);
3604 if(apple) {
3605 /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
3606 * used it falls back to software. While the compiler can detect if the shader uses all declared
3607 * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
3608 * using relative addressing falls back to software.
3610 * ARB vp gives the correct amount of uniforms, so use it instead of GLSL
3612 if(gl_info->vs_glsl_constantsF <= gl_info->vs_arb_constantsF) {
3613 FIXME("GLSL doesn't advertise more vertex shader uniforms than ARB. Driver fixup outdated?\n");
3614 } else {
3615 TRACE("Driver claims %u GLSL vs uniforms, replacing with %u ARB vp uniforms\n",
3616 gl_info->vs_glsl_constantsF, gl_info->vs_arb_constantsF);
3617 gl_info->vs_glsl_constantsF = gl_info->vs_arb_constantsF;
3620 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
3621 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
3622 * If real NP2 textures are used, the driver falls back to software. So remove the supported
3623 * flag for this extension
3625 if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] && gl_info->gl_vendor == VENDOR_ATI) {
3626 if(gl_info->gl_card == CARD_ATI_RADEON_X700 || gl_info->gl_card == CARD_ATI_RADEON_X1600 ||
3627 gl_info->gl_card == CARD_ATI_RADEON_9500 || gl_info->gl_card == CARD_ATI_RADEON_8500 ||
3628 gl_info->gl_card == CARD_ATI_RADEON_7200 || gl_info->gl_card == CARD_ATI_RAGE_128PRO) {
3629 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing\n");
3630 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
3631 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
3635 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
3636 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
3637 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
3638 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
3639 * according to the spec.
3641 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
3642 * makes the shader slower and eats instruction slots which should be available to the d3d app.
3644 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
3645 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
3646 * this workaround is activated on cards that do not need it, it won't break things, just affect
3647 * performance negatively.
3649 if(gl_info->gl_vendor == VENDOR_INTEL ||
3650 (gl_info->gl_vendor == VENDOR_ATI && gl_info->gl_card != CARD_ATI_RADEON_X1600)) {
3651 TRACE("Enabling vertex texture coord fixes in vertex shaders\n");
3652 gl_info->set_texcoord_w = TRUE;
3656 /* Find out if PBOs work as they are supposed to */
3657 test_pbo_functionality(gl_info);
3659 /* Fixup the driver version */
3660 for(i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++) {
3661 if(gl_info->gl_vendor == driver_version_table[i].vendor &&
3662 gl_info->gl_card == driver_version_table[i].card) {
3663 TRACE_(d3d_caps)("Found card 0x%04x, 0x%04x in driver version DB\n", gl_info->gl_vendor, gl_info->gl_card);
3665 gl_info->driver_version = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
3666 driver_version_table[i].lopart_lo);
3667 gl_info->driver_version_hipart = MAKEDWORD_VERSION(driver_version_table[i].hipart_hi,
3668 driver_version_table[i].hipart_lo);
3669 break;
3674 void invalid_func(void *data) {
3675 ERR("Invalid vertex attribute function called\n");
3676 DebugBreak();
3679 #define GLINFO_LOCATION (Adapters[0].gl_info)
3681 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
3682 * the extension detection and are used in drawStridedSlow
3684 static void position_d3dcolor(void *data) {
3685 DWORD pos = *((DWORD *) data);
3687 FIXME("Add a test for fixed function position from d3dcolor type\n");
3688 glVertex4s(D3DCOLOR_B_R(pos),
3689 D3DCOLOR_B_G(pos),
3690 D3DCOLOR_B_B(pos),
3691 D3DCOLOR_B_A(pos));
3693 static void position_float4(void *data) {
3694 GLfloat *pos = (float *) data;
3696 if (pos[3] < eps && pos[3] > -eps)
3697 glVertex3fv(pos);
3698 else {
3699 float w = 1.0 / pos[3];
3701 glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
3705 static void diffuse_d3dcolor(void *data) {
3706 DWORD diffuseColor = *((DWORD *) data);
3708 glColor4ub(D3DCOLOR_B_R(diffuseColor),
3709 D3DCOLOR_B_G(diffuseColor),
3710 D3DCOLOR_B_B(diffuseColor),
3711 D3DCOLOR_B_A(diffuseColor));
3714 static void specular_d3dcolor(void *data) {
3715 DWORD specularColor = *((DWORD *) data);
3717 GL_EXTCALL(glSecondaryColor3ubEXT)(D3DCOLOR_B_R(specularColor),
3718 D3DCOLOR_B_G(specularColor),
3719 D3DCOLOR_B_B(specularColor));
3721 static void warn_no_specular_func(void *data) {
3722 WARN("GL_EXT_secondary_color not supported\n");
3725 void fillGLAttribFuncs(WineD3D_GL_Info *gl_info) {
3726 position_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3727 position_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3728 position_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glVertex3fv;
3729 position_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) position_float4;
3730 position_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) position_d3dcolor;
3731 position_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3732 position_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3733 position_funcs[WINED3DDECLTYPE_SHORT4] = (void *) glVertex2sv;
3734 position_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3735 position_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3736 position_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3737 position_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3738 position_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3739 position_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3740 position_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3741 position_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3742 position_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3744 diffuse_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3745 diffuse_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3746 diffuse_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glColor3fv;
3747 diffuse_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) glColor4fv;
3748 diffuse_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) diffuse_d3dcolor;
3749 diffuse_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3750 diffuse_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3751 diffuse_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3752 diffuse_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) glColor4ubv;
3753 diffuse_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3754 diffuse_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) glColor4sv;
3755 diffuse_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3756 diffuse_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) glColor4usv;
3757 diffuse_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3758 diffuse_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3759 diffuse_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3760 diffuse_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3762 /* No 4 component entry points here */
3763 specular_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3764 specular_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3765 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
3766 specular_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) GL_EXTCALL(glSecondaryColor3fvEXT);
3767 } else {
3768 specular_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) warn_no_specular_func;
3770 specular_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) invalid_func;
3771 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
3772 specular_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) specular_d3dcolor;
3773 } else {
3774 specular_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) warn_no_specular_func;
3776 specular_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3777 specular_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3778 specular_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3779 specular_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3780 specular_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3781 specular_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3782 specular_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3783 specular_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3784 specular_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3785 specular_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3786 specular_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3787 specular_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3789 /* Only 3 component entry points here. Test how others behave. Float4 normals are used
3790 * by one of our tests, trying to pass it to the pixel shader, which fails on Windows.
3792 normal_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3793 normal_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3794 normal_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glNormal3fv;
3795 normal_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) glNormal3fv; /* Just ignore the 4th value */
3796 normal_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) invalid_func;
3797 normal_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3798 normal_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3799 normal_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3800 normal_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3801 normal_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3802 normal_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3803 normal_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3804 normal_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3805 normal_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3806 normal_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3807 normal_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3808 normal_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3811 #define PUSH1(att) attribs[nAttribs++] = (att);
3812 BOOL InitAdapters(void) {
3813 static HMODULE mod_gl;
3814 BOOL ret;
3815 int ps_selected_mode, vs_selected_mode;
3817 /* No need to hold any lock. The calling library makes sure only one thread calls
3818 * wined3d simultaneously
3820 if(numAdapters > 0) return Adapters[0].opengl;
3822 TRACE("Initializing adapters\n");
3824 if(!mod_gl) {
3825 #ifdef USE_WIN32_OPENGL
3826 #define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
3827 mod_gl = LoadLibraryA("opengl32.dll");
3828 if(!mod_gl) {
3829 ERR("Can't load opengl32.dll!\n");
3830 goto nogl_adapter;
3832 #else
3833 #define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
3834 /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
3835 mod_gl = GetModuleHandleA("gdi32.dll");
3836 #endif
3839 /* Load WGL core functions from opengl32.dll */
3840 #define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn);
3841 WGL_FUNCS_GEN;
3842 #undef USE_WGL_FUNC
3844 if(!pwglGetProcAddress) {
3845 ERR("Unable to load wglGetProcAddress!\n");
3846 goto nogl_adapter;
3849 /* Dynamically load all GL core functions */
3850 GL_FUNCS_GEN;
3851 #undef USE_GL_FUNC
3853 /* For now only one default adapter */
3855 int iPixelFormat;
3856 int attribs[10];
3857 int values[10];
3858 int nAttribs = 0;
3859 int res;
3860 int i;
3861 WineD3D_PixelFormat *cfgs;
3862 int attribute;
3863 DISPLAY_DEVICEW DisplayDevice;
3864 HDC hdc;
3866 TRACE("Initializing default adapter\n");
3867 Adapters[0].num = 0;
3868 Adapters[0].monitorPoint.x = -1;
3869 Adapters[0].monitorPoint.y = -1;
3871 if (!WineD3D_CreateFakeGLContext()) {
3872 ERR("Failed to get a gl context for default adapter\n");
3873 WineD3D_ReleaseFakeGLContext();
3874 goto nogl_adapter;
3877 ret = IWineD3DImpl_FillGLCaps(&Adapters[0].gl_info);
3878 if(!ret) {
3879 ERR("Failed to initialize gl caps for default adapter\n");
3880 WineD3D_ReleaseFakeGLContext();
3881 goto nogl_adapter;
3883 ret = initPixelFormats(&Adapters[0].gl_info);
3884 if(!ret) {
3885 ERR("Failed to init gl formats\n");
3886 WineD3D_ReleaseFakeGLContext();
3887 goto nogl_adapter;
3890 hdc = pwglGetCurrentDC();
3891 if(!hdc) {
3892 ERR("Failed to get gl HDC\n");
3893 WineD3D_ReleaseFakeGLContext();
3894 goto nogl_adapter;
3897 Adapters[0].driver = "Display";
3898 Adapters[0].description = "Direct3D HAL";
3900 /* Use the VideoRamSize registry setting when set */
3901 if(wined3d_settings.emulated_textureram)
3902 Adapters[0].TextureRam = wined3d_settings.emulated_textureram;
3903 else
3904 Adapters[0].TextureRam = Adapters[0].gl_info.vidmem;
3905 Adapters[0].UsedTextureRam = 0;
3906 TRACE("Emulating %dMB of texture ram\n", Adapters[0].TextureRam/(1024*1024));
3908 /* Initialize the Adapter's DeviceName which is required for ChangeDisplaySettings and friends */
3909 DisplayDevice.cb = sizeof(DisplayDevice);
3910 EnumDisplayDevicesW(NULL, 0 /* Adapter 0 = iDevNum 0 */, &DisplayDevice, 0);
3911 TRACE("DeviceName: %s\n", debugstr_w(DisplayDevice.DeviceName));
3912 strcpyW(Adapters[0].DeviceName, DisplayDevice.DeviceName);
3914 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
3915 GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, &attribute, &Adapters[0].nCfgs));
3917 Adapters[0].cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Adapters[0].nCfgs *sizeof(WineD3D_PixelFormat));
3918 cfgs = Adapters[0].cfgs;
3919 PUSH1(WGL_RED_BITS_ARB)
3920 PUSH1(WGL_GREEN_BITS_ARB)
3921 PUSH1(WGL_BLUE_BITS_ARB)
3922 PUSH1(WGL_ALPHA_BITS_ARB)
3923 PUSH1(WGL_DEPTH_BITS_ARB)
3924 PUSH1(WGL_STENCIL_BITS_ARB)
3925 PUSH1(WGL_DRAW_TO_WINDOW_ARB)
3926 PUSH1(WGL_PIXEL_TYPE_ARB)
3927 PUSH1(WGL_DOUBLE_BUFFER_ARB)
3928 PUSH1(WGL_AUX_BUFFERS_ARB)
3930 for(iPixelFormat=1; iPixelFormat<=Adapters[0].nCfgs; iPixelFormat++) {
3931 res = GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, nAttribs, attribs, values));
3933 if(!res)
3934 continue;
3936 /* Cache the pixel format */
3937 cfgs->iPixelFormat = iPixelFormat;
3938 cfgs->redSize = values[0];
3939 cfgs->greenSize = values[1];
3940 cfgs->blueSize = values[2];
3941 cfgs->alphaSize = values[3];
3942 cfgs->depthSize = values[4];
3943 cfgs->stencilSize = values[5];
3944 cfgs->windowDrawable = values[6];
3945 cfgs->iPixelType = values[7];
3946 cfgs->doubleBuffer = values[8];
3947 cfgs->auxBuffers = values[9];
3949 cfgs->pbufferDrawable = FALSE;
3950 /* Check for pbuffer support when it is around as wglGetPixelFormatAttribiv fails for unknown attributes. */
3951 if(GL_SUPPORT(WGL_ARB_PBUFFER)) {
3952 int attrib = WGL_DRAW_TO_PBUFFER_ARB;
3953 int value;
3954 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 1, &attrib, &value)))
3955 cfgs->pbufferDrawable = value;
3958 cfgs->numSamples = 0;
3959 /* Check multisample support */
3960 if(GL_SUPPORT(ARB_MULTISAMPLE)) {
3961 int attrib[2] = {WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB};
3962 int value[2];
3963 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 2, attrib, value))) {
3964 /* value[0] = WGL_SAMPLE_BUFFERS_ARB which tells whether multisampling is supported.
3965 * value[1] = number of multi sample buffers*/
3966 if(value[0])
3967 cfgs->numSamples = value[1];
3971 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);
3972 cfgs++;
3975 /* D16, D24X8 and D24S8 are common depth / depth+stencil formats. All drivers support them though this doesn't
3976 * mean that the format is offered in hardware. For instance Geforce8 cards don't have offer D16 in hardware
3977 * but just fake it using D24(X8?) which is fine. D3D also allows that.
3978 * Some display drivers (i915 on Linux) only report mixed depth+stencil formats like D24S8. MSDN clearly mentions
3979 * that only on lockable formats (e.g. D16_locked) the bit order is guaranteed and that on other formats the
3980 * driver is allowed to consume more bits EXCEPT for stencil bits.
3982 * Mark an adapter with this broken stencil behavior.
3984 Adapters[0].brokenStencil = TRUE;
3985 for(i=0, cfgs=Adapters[0].cfgs; i<Adapters[0].nCfgs; i++) {
3986 /* Nearly all drivers offer depth formats without stencil, only on i915 this if-statement won't be entered. */
3987 if(cfgs[i].depthSize && !cfgs[i].stencilSize) {
3988 Adapters[0].brokenStencil = FALSE;
3989 break;
3993 fixup_extensions(&Adapters[0].gl_info);
3995 WineD3D_ReleaseFakeGLContext();
3997 select_shader_mode(&Adapters[0].gl_info, WINED3DDEVTYPE_HAL, &ps_selected_mode, &vs_selected_mode);
3998 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &Adapters[0].gl_info);
3999 fillGLAttribFuncs(&Adapters[0].gl_info);
4000 init_type_lookup(&Adapters[0].gl_info);
4001 Adapters[0].opengl = TRUE;
4003 numAdapters = 1;
4004 TRACE("%d adapters successfully initialized\n", numAdapters);
4006 return TRUE;
4008 nogl_adapter:
4009 /* Initialize an adapter for ddraw-only memory counting */
4010 memset(Adapters, 0, sizeof(Adapters));
4011 Adapters[0].num = 0;
4012 Adapters[0].opengl = FALSE;
4013 Adapters[0].monitorPoint.x = -1;
4014 Adapters[0].monitorPoint.y = -1;
4016 Adapters[0].driver = "Display";
4017 Adapters[0].description = "WineD3D DirectDraw Emulation";
4018 if(wined3d_settings.emulated_textureram) {
4019 Adapters[0].TextureRam = wined3d_settings.emulated_textureram;
4020 } else {
4021 Adapters[0].TextureRam = 8 * 1024 * 1024; /* This is plenty for a DDraw-only card */
4024 numAdapters = 1;
4025 return FALSE;
4027 #undef PUSH1
4028 #undef GLINFO_LOCATION
4030 /**********************************************************
4031 * IWineD3D VTbl follows
4032 **********************************************************/
4034 const IWineD3DVtbl IWineD3D_Vtbl =
4036 /* IUnknown */
4037 IWineD3DImpl_QueryInterface,
4038 IWineD3DImpl_AddRef,
4039 IWineD3DImpl_Release,
4040 /* IWineD3D */
4041 IWineD3DImpl_GetParent,
4042 IWineD3DImpl_GetAdapterCount,
4043 IWineD3DImpl_RegisterSoftwareDevice,
4044 IWineD3DImpl_GetAdapterMonitor,
4045 IWineD3DImpl_GetAdapterModeCount,
4046 IWineD3DImpl_EnumAdapterModes,
4047 IWineD3DImpl_GetAdapterDisplayMode,
4048 IWineD3DImpl_GetAdapterIdentifier,
4049 IWineD3DImpl_CheckDeviceMultiSampleType,
4050 IWineD3DImpl_CheckDepthStencilMatch,
4051 IWineD3DImpl_CheckDeviceType,
4052 IWineD3DImpl_CheckDeviceFormat,
4053 IWineD3DImpl_CheckDeviceFormatConversion,
4054 IWineD3DImpl_GetDeviceCaps,
4055 IWineD3DImpl_CreateDevice