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