wined3d: Fix copy and past error.
[wine/gsoc_dplay.git] / dlls / wined3d / directx.c
blob04af700e8f67610aa1a0c83d78a66a9f8fb966e8
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
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 /* Compile time diagnostics: */
26 #ifndef DEBUG_SINGLE_MODE
27 /* Set to 1 to force only a single display mode to be exposed: */
28 #define DEBUG_SINGLE_MODE 0
29 #endif
32 #include "config.h"
33 #include <assert.h>
34 #include "wined3d_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
37 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
39 /* Extension detection */
40 static const struct {
41 const char *extension_string;
42 GL_SupportedExt extension;
43 DWORD version;
44 } EXTENSION_MAP[] = {
45 /* APPLE */
46 {"GL_APPLE_client_storage", APPLE_CLIENT_STORAGE, 0 },
47 {"GL_APPLE_fence", APPLE_FENCE, 0 },
48 {"GL_APPLE_flush_render", APPLE_FLUSH_RENDER, 0 },
49 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422, 0 },
50 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS, 0 },
52 /* ATI */
53 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL, 0 },
54 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3, 0 },
55 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE, 0 },
56 {"GL_ATI_envmap_bumpmap", ATI_ENVMAP_BUMPMAP, 0 },
58 /* ARB */
59 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS, 0 },
60 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM, 0 },
61 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER, 0 },
62 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL, 0 },
63 {"GL_ARB_imaging", ARB_IMAGING, 0 },
64 {"GL_ARB_multisample", ARB_MULTISAMPLE, 0 }, /* needs GLX_ARB_MULTISAMPLE as well */
65 {"GL_ARB_multitexture", ARB_MULTITEXTURE, 0 },
66 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY, 0 },
67 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT, 0 },
68 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS, 0 },
69 {"GL_ARB_point_sprite", ARB_POINT_SPRITE, 0 },
70 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP, 0 },
71 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION, 0 },
72 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP, 0 },
73 {"GL_ARB_texture_env_add", ARB_TEXTURE_ENV_ADD, 0 },
74 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE, 0 },
75 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3, 0 },
76 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT, 0 },
77 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT, 0 },
78 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO, 0 },
79 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE, 0 },
80 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND, 0 },
81 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT, 0 },
82 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM, 0 },
83 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER, 0 },
84 {"GL_ARB_shader_objects", ARB_SHADER_OBJECTS, 0 },
86 /* EXT */
87 {"GL_EXT_blend_color", EXT_BLEND_COLOR, 0 },
88 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX, 0 },
89 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE, 0 },
90 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE, 0 },
91 {"GL_EXT_fog_coord", EXT_FOG_COORD, 0 },
92 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT, 0 },
93 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT, 0 },
94 {"GL_EXT_paletted_texture", EXT_PALETTED_TEXTURE, 0 },
95 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS, 0 },
96 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR, 0 },
97 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE, 0 },
98 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP, 0 },
99 {"GL_EXT_texture3D", EXT_TEXTURE3D, MAKEDWORD_VERSION(1, 2) },
100 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC, 0 },
101 {"GL_EXT_texture_env_add", EXT_TEXTURE_ENV_ADD, 0 },
102 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE, 0 },
103 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3, 0 },
104 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB, 0 },
105 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC, 0 },
106 {"GL_EXT_texture_lod", EXT_TEXTURE_LOD, 0 },
107 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS, 0 },
108 {"GL_EXT_vertex_shader", EXT_VERTEX_SHADER, 0 },
109 {"GL_EXT_vertex_weighting", EXT_VERTEX_WEIGHTING, 0 },
110 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS, 0 },
112 /* NV */
113 {"GL_NV_half_float", NV_HALF_FLOAT, 0 },
114 {"GL_NV_fence", NV_FENCE, 0 },
115 {"GL_NV_fog_distance", NV_FOG_DISTANCE, 0 },
116 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM, 0 },
117 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2, 0 },
118 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS, 0 },
119 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2, 0 },
120 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION, 0 },
121 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4, 0 },
122 {"GL_NV_texture_shader", NV_TEXTURE_SHADER, 0 },
123 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2, 0 },
124 {"GL_NV_texture_shader3", NV_TEXTURE_SHADER3, 0 },
125 {"GL_NV_occlusion_query", NV_OCCLUSION_QUERY, 0 },
126 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM, 0 },
127 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1, 0 },
128 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2, 0 },
129 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3, 0 },
130 {"GL_NV_depth_clamp", NV_DEPTH_CLAMP, 0 },
131 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT, 0 },
133 /* SGI */
134 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP, 0 },
137 /**********************************************************
138 * Utility functions follow
139 **********************************************************/
141 /* Adapters */
142 static int numAdapters = 0;
143 static struct WineD3DAdapter Adapters[1];
145 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat);
147 /* lookup tables */
148 int minLookup[MAX_LOOKUPS];
149 int maxLookup[MAX_LOOKUPS];
150 DWORD *stateLookup[MAX_LOOKUPS];
152 DWORD minMipLookup[WINED3DTEXF_ANISOTROPIC + 1][WINED3DTEXF_LINEAR + 1];
154 /* drawStridedSlow attributes */
155 glAttribFunc position_funcs[WINED3DDECLTYPE_UNUSED];
156 glAttribFunc diffuse_funcs[WINED3DDECLTYPE_UNUSED];
157 glAttribFunc specular_funcs[WINED3DDECLTYPE_UNUSED];
158 glAttribFunc normal_funcs[WINED3DDECLTYPE_UNUSED];
159 glTexAttribFunc texcoord_funcs[WINED3DDECLTYPE_UNUSED];
162 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created
163 * ie there is no GL Context - Get a default rendering context to enable the
164 * function query some info from GL
167 static int wined3d_fake_gl_context_ref = 0;
168 static BOOL wined3d_fake_gl_context_foreign;
169 static BOOL wined3d_fake_gl_context_available = FALSE;
170 static HDC wined3d_fake_gl_context_hdc = NULL;
171 static HWND wined3d_fake_gl_context_hwnd = NULL;
173 static CRITICAL_SECTION wined3d_fake_gl_context_cs;
174 static CRITICAL_SECTION_DEBUG wined3d_fake_gl_context_cs_debug =
176 0, 0, &wined3d_fake_gl_context_cs,
177 { &wined3d_fake_gl_context_cs_debug.ProcessLocksList,
178 &wined3d_fake_gl_context_cs_debug.ProcessLocksList },
179 0, 0, { (DWORD_PTR)(__FILE__ ": wined3d_fake_gl_context_cs") }
181 static CRITICAL_SECTION wined3d_fake_gl_context_cs = { &wined3d_fake_gl_context_cs_debug, -1, 0, 0, 0, 0 };
183 static void WineD3D_ReleaseFakeGLContext(void) {
184 HGLRC glCtx;
186 EnterCriticalSection(&wined3d_fake_gl_context_cs);
188 if(!wined3d_fake_gl_context_available) {
189 TRACE_(d3d_caps)("context not available\n");
190 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
191 return;
194 glCtx = pwglGetCurrentContext();
196 TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref);
197 if (0 == (--wined3d_fake_gl_context_ref) ) {
198 if(!wined3d_fake_gl_context_foreign && glCtx) {
199 TRACE_(d3d_caps)("destroying fake GL context\n");
200 pwglMakeCurrent(NULL, NULL);
201 pwglDeleteContext(glCtx);
203 if(wined3d_fake_gl_context_hdc)
204 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
205 wined3d_fake_gl_context_hdc = NULL; /* Make sure we don't think that it is still around */
206 if(wined3d_fake_gl_context_hwnd)
207 DestroyWindow(wined3d_fake_gl_context_hwnd);
208 wined3d_fake_gl_context_hwnd = NULL;
209 wined3d_fake_gl_context_available = FALSE;
211 assert(wined3d_fake_gl_context_ref >= 0);
213 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
216 static BOOL WineD3D_CreateFakeGLContext(void) {
217 HGLRC glCtx = NULL;
219 EnterCriticalSection(&wined3d_fake_gl_context_cs);
221 TRACE("getting context...\n");
222 if(wined3d_fake_gl_context_ref > 0) goto ret;
223 assert(0 == wined3d_fake_gl_context_ref);
225 wined3d_fake_gl_context_foreign = TRUE;
227 glCtx = pwglGetCurrentContext();
228 if (!glCtx) {
229 PIXELFORMATDESCRIPTOR pfd;
230 int iPixelFormat;
232 wined3d_fake_gl_context_foreign = FALSE;
234 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes */
235 wined3d_fake_gl_context_hwnd = CreateWindowA("WineD3D_OpenGL", "WineD3D fake window", WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
236 if(!wined3d_fake_gl_context_hwnd) {
237 ERR("HWND creation failed!\n");
238 goto fail;
240 wined3d_fake_gl_context_hdc = GetDC(wined3d_fake_gl_context_hwnd);
241 if(!wined3d_fake_gl_context_hdc) {
242 ERR("GetDC failed!\n");
243 goto fail;
246 /* PixelFormat selection */
247 ZeroMemory(&pfd, sizeof(pfd));
248 pfd.nSize = sizeof(pfd);
249 pfd.nVersion = 1;
250 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;/*PFD_GENERIC_ACCELERATED*/
251 pfd.iPixelType = PFD_TYPE_RGBA;
252 pfd.cColorBits = 32;
253 pfd.iLayerType = PFD_MAIN_PLANE;
255 iPixelFormat = ChoosePixelFormat(wined3d_fake_gl_context_hdc, &pfd);
256 if(!iPixelFormat) {
257 /* If this happens something is very wrong as ChoosePixelFormat barely fails */
258 ERR("Can't find a suitable iPixelFormat\n");
259 goto fail;
261 DescribePixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, sizeof(pfd), &pfd);
262 SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd);
264 /* Create a GL context */
265 glCtx = pwglCreateContext(wined3d_fake_gl_context_hdc);
266 if (!glCtx) {
267 WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
268 goto fail;
271 /* Make it the current GL context */
272 if (!pwglMakeCurrent(wined3d_fake_gl_context_hdc, glCtx)) {
273 WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
274 goto fail;
278 ret:
279 TRACE("incrementing ref from %i\n", wined3d_fake_gl_context_ref);
280 wined3d_fake_gl_context_ref++;
281 wined3d_fake_gl_context_available = TRUE;
282 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
283 return TRUE;
284 fail:
285 if(wined3d_fake_gl_context_hdc)
286 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
287 wined3d_fake_gl_context_hdc = NULL;
288 if(wined3d_fake_gl_context_hwnd)
289 DestroyWindow(wined3d_fake_gl_context_hwnd);
290 wined3d_fake_gl_context_hwnd = NULL;
291 if(glCtx) pwglDeleteContext(glCtx);
292 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
293 return FALSE;
296 /* Adjust the amount of used texture memory */
297 long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram){
298 UINT Adapter = D3DDevice->adapterNo;
300 Adapters[Adapter].UsedTextureRam += glram;
301 TRACE("Adjusted gl ram by %ld to %d\n", glram, Adapters[Adapter].UsedTextureRam);
302 return Adapters[Adapter].UsedTextureRam;
305 /**********************************************************
306 * IUnknown parts follows
307 **********************************************************/
309 static HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
311 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
313 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
314 if (IsEqualGUID(riid, &IID_IUnknown)
315 || IsEqualGUID(riid, &IID_IWineD3DBase)
316 || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
317 IUnknown_AddRef(iface);
318 *ppobj = This;
319 return S_OK;
321 *ppobj = NULL;
322 return E_NOINTERFACE;
325 static ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
326 IWineD3DImpl *This = (IWineD3DImpl *)iface;
327 ULONG refCount = InterlockedIncrement(&This->ref);
329 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
330 return refCount;
333 static ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
334 IWineD3DImpl *This = (IWineD3DImpl *)iface;
335 ULONG ref;
336 TRACE("(%p) : Releasing from %d\n", This, This->ref);
337 ref = InterlockedDecrement(&This->ref);
338 if (ref == 0) {
339 HeapFree(GetProcessHeap(), 0, This);
342 return ref;
345 /* Set the shader type for this device, depending on the given capabilities,
346 * the device type, and the user preferences in wined3d_settings */
348 static void select_shader_mode(
349 WineD3D_GL_Info *gl_info,
350 WINED3DDEVTYPE DeviceType,
351 int* ps_selected,
352 int* vs_selected) {
354 if (wined3d_settings.vs_mode == VS_NONE) {
355 *vs_selected = SHADER_NONE;
356 } else if (gl_info->supported[ARB_VERTEX_SHADER] && wined3d_settings.glslRequested) {
357 /* Geforce4 cards support GLSL but for vertex shaders only. Further its reported GLSL caps are
358 * wrong. This combined with the fact that glsl won't offer more features or performance, use ARB
359 * shaders only on this card. */
360 if(gl_info->vs_nv_version && gl_info->vs_nv_version < VS_VERSION_20)
361 *vs_selected = SHADER_ARB;
362 else
363 *vs_selected = SHADER_GLSL;
364 } else if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
365 *vs_selected = SHADER_ARB;
366 } else {
367 *vs_selected = SHADER_NONE;
370 if (wined3d_settings.ps_mode == PS_NONE) {
371 *ps_selected = SHADER_NONE;
372 } else if (gl_info->supported[ARB_FRAGMENT_SHADER] && wined3d_settings.glslRequested) {
373 *ps_selected = SHADER_GLSL;
374 } else if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
375 *ps_selected = SHADER_ARB;
376 } else {
377 *ps_selected = SHADER_NONE;
381 /** Select the number of report maximum shader constants based on the selected shader modes */
382 static void select_shader_max_constants(
383 int ps_selected_mode,
384 int vs_selected_mode,
385 WineD3D_GL_Info *gl_info) {
387 switch (vs_selected_mode) {
388 case SHADER_GLSL:
389 /* Subtract the other potential uniforms from the max available (bools, ints, and 1 row of projection matrix) */
390 gl_info->max_vshader_constantsF = gl_info->vs_glsl_constantsF - (MAX_CONST_B / 4) - MAX_CONST_I - 1;
391 break;
392 case SHADER_ARB:
393 /* We have to subtract any other PARAMs that we might use in our shader programs.
394 * ATI seems to count 2 implicit PARAMs when we use fog and NVIDIA counts 1,
395 * and we reference one row of the PROJECTION matrix which counts as 1 PARAM. */
396 gl_info->max_vshader_constantsF = gl_info->vs_arb_constantsF - 3;
397 break;
398 default:
399 gl_info->max_vshader_constantsF = 0;
400 break;
403 switch (ps_selected_mode) {
404 case SHADER_GLSL:
405 /* Subtract the other potential uniforms from the max available (bools & ints), and 2 states for fog.
406 * In theory the texbem instruction may need one more shader constant too. But lets assume
407 * that a sm <= 1.3 shader does not need all the uniforms provided by a glsl-capable card,
408 * and lets not take away a uniform needlessly from all other shaders.
410 gl_info->max_pshader_constantsF = gl_info->ps_glsl_constantsF - (MAX_CONST_B / 4) - MAX_CONST_I - 2;
411 break;
412 case SHADER_ARB:
413 /* The arb shader only loads the bump mapping environment matrix into the shader if it finds
414 * a free constant to do that, so only reduce the number of available constants by 2 for the fog states.
416 gl_info->max_pshader_constantsF = gl_info->ps_arb_constantsF - 2;
417 break;
418 default:
419 gl_info->max_pshader_constantsF = 0;
420 break;
424 /**********************************************************
425 * IWineD3D parts follows
426 **********************************************************/
428 #define GLINFO_LOCATION (*gl_info)
429 static inline BOOL test_arb_vs_offset_limit(WineD3D_GL_Info *gl_info) {
430 GLuint prog;
431 BOOL ret = FALSE;
432 const char *testcode =
433 "!!ARBvp1.0\n"
434 "PARAM C[66] = { program.env[0..65] };\n"
435 "ADDRESS A0;"
436 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
437 "ARL A0.x, zero.x;\n"
438 "MOV result.position, C[A0.x + 65];\n"
439 "END\n";
441 while(glGetError());
442 GL_EXTCALL(glGenProgramsARB(1, &prog));
443 if(!prog) {
444 ERR("Failed to create an ARB offset limit test program\n");
446 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
447 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
448 strlen(testcode), testcode));
449 if(glGetError() != 0) {
450 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
451 TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
452 ret = TRUE;
453 } else TRACE("OpenGL implementation allows offsets > 63\n");
455 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
456 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
457 checkGLcall("ARB vp offset limit test cleanup\n");
459 return ret;
462 static DWORD ver_for_ext(GL_SupportedExt ext)
464 unsigned int i;
465 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
466 if(EXTENSION_MAP[i].extension == ext) {
467 return EXTENSION_MAP[i].version;
470 return 0;
473 BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
474 const char *GL_Extensions = NULL;
475 const char *WGL_Extensions = NULL;
476 const char *gl_string = NULL;
477 const char *gl_string_cursor = NULL;
478 GLint gl_max;
479 GLfloat gl_floatv[2];
480 int major = 1, minor = 0;
481 BOOL return_value = TRUE;
482 unsigned i;
483 HDC hdc;
484 unsigned int vidmem=0;
486 TRACE_(d3d_caps)("(%p)\n", gl_info);
488 ENTER_GL();
490 gl_string = (const char *) glGetString(GL_RENDERER);
491 if (NULL == gl_string)
492 gl_string = "None";
493 strcpy(gl_info->gl_renderer, gl_string);
495 gl_string = (const char *) glGetString(GL_VENDOR);
496 TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
497 if (gl_string != NULL) {
498 /* Fill in the GL vendor */
499 if (strstr(gl_string, "NVIDIA")) {
500 gl_info->gl_vendor = VENDOR_NVIDIA;
501 } else if (strstr(gl_string, "ATI")) {
502 gl_info->gl_vendor = VENDOR_ATI;
503 } else if (strstr(gl_string, "Intel(R)") ||
504 strstr(gl_info->gl_renderer, "Intel(R)") ||
505 strstr(gl_string, "Intel Inc.")) {
506 gl_info->gl_vendor = VENDOR_INTEL;
507 } else if (strstr(gl_string, "Mesa")) {
508 gl_info->gl_vendor = VENDOR_MESA;
509 } else {
510 gl_info->gl_vendor = VENDOR_WINE;
512 } else {
513 gl_info->gl_vendor = VENDOR_WINE;
517 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
519 /* Parse the GL_VERSION field into major and minor information */
520 gl_string = (const char *) glGetString(GL_VERSION);
521 if (gl_string != NULL) {
523 /* First, parse the generic opengl version. This is supposed not to be convoluted with
524 * driver specific information
526 gl_string_cursor = gl_string;
527 major = atoi(gl_string_cursor);
528 if(major <= 0) {
529 ERR("Invalid opengl major version: %d\n", major);
531 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
532 ++gl_string_cursor;
534 if (*gl_string_cursor++ != '.') {
535 ERR_(d3d_caps)("Invalid opengl version string: %s\n", debugstr_a(gl_string));
537 minor = atoi(gl_string_cursor);
538 TRACE_(d3d_caps)("Found OpenGL version: %d.%d\n", major, minor);
539 gl_info->gl_version = MAKEDWORD_VERSION(major, minor);
541 /* Now parse the driver specific string which we'll report to the app */
542 switch (gl_info->gl_vendor) {
543 case VENDOR_NVIDIA:
544 gl_string_cursor = strstr(gl_string, "NVIDIA");
545 if (!gl_string_cursor) {
546 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
547 break;
550 gl_string_cursor = strstr(gl_string_cursor, " ");
551 if (!gl_string_cursor) {
552 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
553 break;
556 while (*gl_string_cursor == ' ') {
557 ++gl_string_cursor;
560 if (!*gl_string_cursor) {
561 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
562 break;
565 major = atoi(gl_string_cursor);
566 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
567 ++gl_string_cursor;
570 if (*gl_string_cursor++ != '.') {
571 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
572 break;
575 minor = atoi(gl_string_cursor);
576 minor = major*100+minor;
577 major = 10;
579 break;
581 case VENDOR_ATI:
582 major = minor = 0;
583 gl_string_cursor = strchr(gl_string, '-');
584 if (gl_string_cursor) {
585 int error = 0;
586 gl_string_cursor++;
588 /* Check if version number is of the form x.y.z */
589 if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
590 error = 1;
591 if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
592 error = 1;
593 if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
594 error = 1;
595 if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
596 error = 1;
598 /* Mark version number as malformed */
599 if (error)
600 gl_string_cursor = 0;
603 if (!gl_string_cursor)
604 WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
605 else {
606 major = *gl_string_cursor - '0';
607 minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
609 break;
611 case VENDOR_INTEL:
612 /* Apple and Mesa version strings look differently, but both provide intel drivers */
613 if(strstr(gl_string, "APPLE")) {
614 /* [0-9]+.[0-9]+ APPLE-[0-9]+.[0.9]+.[0.9]+
615 * We only need the first part, and use the APPLE as identification
616 * "1.2 APPLE-1.4.56"
618 gl_string_cursor = gl_string;
619 major = atoi(gl_string_cursor);
620 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
621 ++gl_string_cursor;
624 if (*gl_string_cursor++ != '.') {
625 ERR_(d3d_caps)("Invalid MacOS-Intel version string: %s\n", debugstr_a(gl_string));
626 break;
629 minor = atoi(gl_string_cursor);
630 break;
633 case VENDOR_MESA:
634 gl_string_cursor = strstr(gl_string, "Mesa");
635 gl_string_cursor = strstr(gl_string_cursor, " ");
636 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
637 if (*gl_string_cursor) {
638 char tmp[16];
639 int cursor = 0;
641 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
642 tmp[cursor++] = *gl_string_cursor;
643 ++gl_string_cursor;
645 tmp[cursor] = 0;
646 major = atoi(tmp);
648 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
649 ++gl_string_cursor;
651 cursor = 0;
652 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
653 tmp[cursor++] = *gl_string_cursor;
654 ++gl_string_cursor;
656 tmp[cursor] = 0;
657 minor = atoi(tmp);
659 break;
661 default:
662 major = 0;
663 minor = 9;
665 gl_info->driver_version = MAKEDWORD_VERSION(major, minor);
666 TRACE_(d3d_caps)("found driver version (%s)->%i.%i->(0x%08x)\n", debugstr_a(gl_string), major, minor, gl_info->driver_version);
667 /* Current Windows drivers have versions like 6.14.... (some older have an earlier version) */
668 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
669 } else {
670 FIXME("OpenGL driver did not return version information\n");
671 gl_info->driver_version = MAKEDWORD_VERSION(0, 0);
672 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
675 TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
678 * Initialize openGL extension related variables
679 * with Default values
681 memset(&gl_info->supported, 0, sizeof(gl_info->supported));
682 gl_info->max_buffers = 1;
683 gl_info->max_textures = 1;
684 gl_info->max_texture_stages = 1;
685 gl_info->max_fragment_samplers = 1;
686 gl_info->max_vertex_samplers = 0;
687 gl_info->max_combined_samplers = 0;
688 gl_info->max_sampler_stages = 1;
689 gl_info->ps_arb_version = PS_VERSION_NOT_SUPPORTED;
690 gl_info->ps_arb_max_temps = 0;
691 gl_info->ps_arb_max_instructions = 0;
692 gl_info->vs_arb_version = VS_VERSION_NOT_SUPPORTED;
693 gl_info->vs_arb_max_temps = 0;
694 gl_info->vs_arb_max_instructions = 0;
695 gl_info->vs_nv_version = VS_VERSION_NOT_SUPPORTED;
696 gl_info->vs_ati_version = VS_VERSION_NOT_SUPPORTED;
697 gl_info->vs_glsl_constantsF = 0;
698 gl_info->ps_glsl_constantsF = 0;
699 gl_info->vs_arb_constantsF = 0;
700 gl_info->ps_arb_constantsF = 0;
702 /* Retrieve opengl defaults */
703 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
704 gl_info->max_clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
705 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
707 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
708 gl_info->max_lights = gl_max;
709 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
711 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
712 gl_info->max_texture_size = gl_max;
713 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
715 glGetFloatv(GL_POINT_SIZE_RANGE, gl_floatv);
716 gl_info->max_pointsizemin = gl_floatv[0];
717 gl_info->max_pointsize = gl_floatv[1];
718 TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
720 glGetIntegerv(GL_AUX_BUFFERS, &gl_max);
721 gl_info->max_aux_buffers = gl_max;
722 TRACE_(d3d_caps)("Offscreen rendering support - number of aux buffers=%d\n", gl_max);
724 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
725 GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
726 TRACE_(d3d_caps)("GL_Extensions reported:\n");
728 if (NULL == GL_Extensions) {
729 ERR(" GL_Extensions returns NULL\n");
730 } else {
731 while (*GL_Extensions != 0x00) {
732 const char *Start;
733 char ThisExtn[256];
734 size_t len;
736 while (isspace(*GL_Extensions)) GL_Extensions++;
737 Start = GL_Extensions;
738 while (!isspace(*GL_Extensions) && *GL_Extensions != 0x00) {
739 GL_Extensions++;
742 len = GL_Extensions - Start;
743 if (len == 0 || len >= sizeof(ThisExtn))
744 continue;
746 memcpy(ThisExtn, Start, len);
747 ThisExtn[len] = '\0';
748 TRACE_(d3d_caps)("- %s\n", ThisExtn);
750 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
751 if (!strcmp(ThisExtn, EXTENSION_MAP[i].extension_string)) {
752 TRACE_(d3d_caps)(" FOUND: %s support\n", EXTENSION_MAP[i].extension_string);
753 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
754 break;
758 /* Now work out what GL support this card really has */
759 #define USE_GL_FUNC(type, pfn, ext, replace) { \
760 DWORD ver = ver_for_ext(ext); \
761 if(gl_info->supported[ext]) gl_info->pfn = (type) pwglGetProcAddress(#pfn); \
762 else if(ver && ver <= gl_info->gl_version) gl_info->pfn = (type) pwglGetProcAddress(#replace); \
763 else gl_info->pfn = NULL; \
765 GL_EXT_FUNCS_GEN;
766 #undef USE_GL_FUNC
768 #define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type) pwglGetProcAddress(#pfn);
769 WGL_EXT_FUNCS_GEN;
770 #undef USE_GL_FUNC
772 /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
773 * loading the functions, otherwise the code above will load the extension entry points instead of the
774 * core functions, which may not work
776 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
777 if (gl_info->supported[EXTENSION_MAP[i].extension] == FALSE &&
778 EXTENSION_MAP[i].version <= gl_info->gl_version && EXTENSION_MAP[i].version) {
779 TRACE_(d3d_caps)(" GL CORE: %s support\n", EXTENSION_MAP[i].extension_string);
780 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
784 if (gl_info->supported[APPLE_FENCE]) {
785 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
786 * The apple extension interacts with some other apple exts. Disable the NV
787 * extension if the apple one is support to prevent confusion in other parts
788 * of the code
790 gl_info->supported[NV_FENCE] = FALSE;
792 if (gl_info->supported[APPLE_FLOAT_PIXELS]) {
793 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
795 * The enums are the same:
796 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881A
797 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881B
798 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
799 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
800 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140B
802 if(!gl_info->supported[ARB_TEXTURE_FLOAT]) {
803 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels\n");
804 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
806 if(!gl_info->supported[ARB_HALF_FLOAT_PIXEL]) {
807 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels\n");
808 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
811 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) {
812 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
813 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
815 if (gl_info->supported[NV_TEXTURE_SHADER2]) {
816 /* GL_ATI_envmap_bumpmap won't play nice with texture shaders, so disable it
817 * Won't occur in any real world situation though
819 gl_info->supported[ATI_ENVMAP_BUMPMAP] = FALSE;
821 if (gl_info->supported[ARB_DRAW_BUFFERS]) {
822 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
823 gl_info->max_buffers = gl_max;
824 TRACE_(d3d_caps)("Max draw buffers: %u\n", gl_max);
826 if (gl_info->supported[ARB_MULTITEXTURE]) {
827 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
828 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
829 TRACE_(d3d_caps)("Max textures: %d\n", gl_info->max_textures);
831 if (gl_info->supported[NV_REGISTER_COMBINERS]) {
832 GLint tmp;
833 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &tmp);
834 gl_info->max_texture_stages = min(MAX_TEXTURES, tmp);
835 } else {
836 gl_info->max_texture_stages = min(MAX_TEXTURES, gl_max);
838 TRACE_(d3d_caps)("Max texture stages: %d\n", gl_info->max_texture_stages);
840 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
841 GLint tmp;
842 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
843 gl_info->max_fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
844 } else {
845 gl_info->max_fragment_samplers = max(gl_info->max_fragment_samplers, gl_max);
847 TRACE_(d3d_caps)("Max fragment samplers: %d\n", gl_info->max_fragment_samplers);
849 if (gl_info->supported[ARB_VERTEX_SHADER]) {
850 GLint tmp;
851 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
852 gl_info->max_vertex_samplers = tmp;
853 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
854 gl_info->max_combined_samplers = tmp;
856 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
857 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
858 * an issue because then the sampler setup only depends on the two shaders. If a pixel
859 * shader is used with fixed function vertex processing we're fine too because fixed function
860 * vertex processing doesn't use any samplers. If fixed function fragment processing is
861 * used we have to make sure that all vertex sampler setups are valid together with all
862 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
863 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
864 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
865 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
866 * a fixed function pipeline anymore.
868 * So this is just a check to check that our assumption holds true. If not, write a warning
869 * and reduce the number of vertex samplers or probably disable vertex texture fetch.
871 if(gl_info->max_vertex_samplers &&
872 MAX_TEXTURES + gl_info->max_vertex_samplers > gl_info->max_combined_samplers) {
873 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers\n",
874 gl_info->max_vertex_samplers, gl_info->max_combined_samplers);
875 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers\n");
876 if( gl_info->max_combined_samplers > MAX_TEXTURES )
877 gl_info->max_vertex_samplers =
878 gl_info->max_combined_samplers - MAX_TEXTURES;
879 else
880 gl_info->max_vertex_samplers = 0;
882 } else {
883 gl_info->max_combined_samplers = gl_info->max_fragment_samplers;
885 TRACE_(d3d_caps)("Max vertex samplers: %u\n", gl_info->max_vertex_samplers);
886 TRACE_(d3d_caps)("Max combined samplers: %u\n", gl_info->max_combined_samplers);
888 if (gl_info->supported[ARB_VERTEX_BLEND]) {
889 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
890 gl_info->max_blends = gl_max;
891 TRACE_(d3d_caps)("Max blends: %u\n", gl_info->max_blends);
893 if (gl_info->supported[EXT_TEXTURE3D]) {
894 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
895 gl_info->max_texture3d_size = gl_max;
896 TRACE_(d3d_caps)("Max texture3D size: %d\n", gl_info->max_texture3d_size);
898 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC]) {
899 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
900 gl_info->max_anisotropy = gl_max;
901 TRACE_(d3d_caps)("Max anisotropy: %d\n", gl_info->max_anisotropy);
903 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
904 gl_info->ps_arb_version = PS_VERSION_11;
905 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
906 gl_info->ps_arb_constantsF = gl_max;
907 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d\n", gl_info->ps_arb_constantsF);
908 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
909 gl_info->ps_arb_max_temps = gl_max;
910 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d\n", gl_info->ps_arb_max_temps);
911 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
912 gl_info->ps_arb_max_instructions = gl_max;
913 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d\n", gl_info->ps_arb_max_instructions);
915 if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
916 gl_info->vs_arb_version = VS_VERSION_11;
917 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
918 gl_info->vs_arb_constantsF = gl_max;
919 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d\n", gl_info->vs_arb_constantsF);
920 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
921 gl_info->vs_arb_max_temps = gl_max;
922 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d\n", gl_info->vs_arb_max_temps);
923 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
924 gl_info->vs_arb_max_instructions = gl_max;
925 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d\n", gl_info->vs_arb_max_instructions);
927 gl_info->arb_vs_offset_limit = test_arb_vs_offset_limit(gl_info);
929 if (gl_info->supported[ARB_VERTEX_SHADER]) {
930 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
931 gl_info->vs_glsl_constantsF = gl_max / 4;
932 TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u\n", gl_info->vs_glsl_constantsF);
934 if (gl_info->supported[ARB_FRAGMENT_SHADER]) {
935 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
936 gl_info->ps_glsl_constantsF = gl_max / 4;
937 TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u\n", gl_info->ps_glsl_constantsF);
938 glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
939 gl_info->max_glsl_varyings = gl_max;
940 TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings)\n", gl_max, gl_max / 4);
942 if (gl_info->supported[EXT_VERTEX_SHADER]) {
943 gl_info->vs_ati_version = VS_VERSION_11;
945 if (gl_info->supported[NV_VERTEX_PROGRAM3]) {
946 gl_info->vs_nv_version = VS_VERSION_30;
947 } else if (gl_info->supported[NV_VERTEX_PROGRAM2]) {
948 gl_info->vs_nv_version = VS_VERSION_20;
949 } else if (gl_info->supported[NV_VERTEX_PROGRAM1_1]) {
950 gl_info->vs_nv_version = VS_VERSION_11;
951 } else if (gl_info->supported[NV_VERTEX_PROGRAM]) {
952 gl_info->vs_nv_version = VS_VERSION_10;
954 if (gl_info->supported[NV_FRAGMENT_PROGRAM2]) {
955 gl_info->ps_nv_version = PS_VERSION_30;
956 } else if (gl_info->supported[NV_FRAGMENT_PROGRAM]) {
957 gl_info->ps_nv_version = PS_VERSION_20;
959 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT]) {
960 glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->max_shininess);
961 } else {
962 gl_info->max_shininess = 128.0;
964 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO]) {
965 /* If we have full NP2 texture support, disable GL_ARB_texture_rectangle because we will never use it.
966 * This saves a few redundant glDisable calls
968 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
972 checkGLcall("extension detection\n");
974 /* In some cases the number of texture stages can be larger than the number
975 * of samplers. The GF4 for example can use only 2 samplers (no fragment
976 * shaders), but 8 texture stages (register combiners). */
977 gl_info->max_sampler_stages = max(gl_info->max_fragment_samplers, gl_info->max_texture_stages);
979 /* We can only use ORM_FBO when the hardware supports it. */
980 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && !gl_info->supported[EXT_FRAMEBUFFER_OBJECT]) {
981 WARN_(d3d_caps)("GL_EXT_framebuffer_object not supported, falling back to PBuffer offscreen rendering mode.\n");
982 wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
985 /* MRTs are currently only supported when FBOs are used. */
986 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) {
987 gl_info->max_buffers = 1;
990 /* Below is a list of Nvidia and ATI GPUs. Both vendors have dozens of different GPUs with roughly the same
991 * features. In most cases GPUs from a certain family differ in clockspeeds, the amount of video memory and
992 * in case of the latest videocards in the number of pixel/vertex pipelines.
994 * A Direct3D device object contains the PCI id (vendor + device) of the videocard which is used for
995 * rendering. Various games use this information to get a rough estimation of the features of the card
996 * and some might use it for enabling 3d effects only on certain types of videocards. In some cases
997 * games might even use it to work around bugs which happen on certain videocards/driver combinations.
998 * The problem is that OpenGL only exposes a rendering string containing the name of the videocard and
999 * not the PCI id.
1001 * Various games depend on the PCI id, so somehow we need to provide one. A simple option is to parse
1002 * the renderer string and translate this to the right PCI id. This is a lot of work because there are more
1003 * than 200 GPUs just for Nvidia. Various cards share the same renderer string, so the amount of code might
1004 * be 'small' but there are quite a number of exceptions which would make this a pain to maintain.
1005 * Another way would be to query the PCI id from the operating system (assuming this is the videocard which
1006 * is used for rendering which is not always the case). This would work but it is not very portable. Second
1007 * it would not work well in, let's say, a remote X situation in which the amount of 3d features which can be used
1008 * is limited.
1010 * As said most games only use the PCI id to get an indication of the capabilities of the card.
1011 * It doesn't really matter if the given id is the correct one if we return the id of a card with
1012 * similar 3d features.
1014 * The code below checks the OpenGL capabilities of a videocard and matches that to a certain level of
1015 * Direct3D functionality. Once a card passes the Direct3D9 check, we know that the card (in case of Nvidia)
1016 * is at least a GeforceFX. To give a better estimate we do a basic check on the renderer string but if that
1017 * won't pass we return a default card. This way is better than maintaining a full card database as even
1018 * without a full database we can return a card with similar features. Second the size of the database
1019 * can be made quite small because when you know what type of 3d functionality a card has, you know to which
1020 * GPU family the GPU must belong. Because of this you only have to check a small part of the renderer string
1021 * to distinguishes between different models from that family.
1023 * The code also selects a default amount of video memory which we will use for an estimation of the amount
1024 * of free texture memory. In case of real D3D the amount of texture memory includes video memory and system
1025 * memory (to be specific AGP memory or in case of PCIE TurboCache/HyperMemory). We don't know how much
1026 * system memory can be addressed by the system but we can make a reasonable estimation about the amount of
1027 * video memory. If the value is slightly wrong it doesn't matter as we didn't include AGP-like memory which
1028 * makes the amount of addressable memory higher and second OpenGL isn't that critical it moves to system
1029 * memory behind our backs if really needed.
1030 * Note that the amount of video memory can be overruled using a registry setting.
1032 switch (gl_info->gl_vendor) {
1033 case VENDOR_NVIDIA:
1034 /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1035 * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1037 if(WINE_D3D9_CAPABLE(gl_info) && (gl_info->vs_nv_version == VS_VERSION_30)) {
1038 /* Geforce8 - highend */
1039 if (strstr(gl_info->gl_renderer, "8800")) {
1040 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8800GTS;
1041 vidmem = 320; /* The 8800GTS uses 320MB, a 8800GTX can have 768MB */
1043 /* Geforce8 - midend mobile */
1044 else if(strstr(gl_info->gl_renderer, "8600 M")) {
1045 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600MGT;
1046 vidmem = 512;
1048 /* Geforce8 - midend */
1049 else if(strstr(gl_info->gl_renderer, "8600") ||
1050 strstr(gl_info->gl_renderer, "8700"))
1052 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600GT;
1053 vidmem = 256;
1055 /* Geforce8 - lowend */
1056 else if(strstr(gl_info->gl_renderer, "8300") ||
1057 strstr(gl_info->gl_renderer, "8400") ||
1058 strstr(gl_info->gl_renderer, "8500"))
1060 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8300GS;
1061 vidmem = 128; /* 128-256MB for a 8300, 256-512MB for a 8400 */
1063 /* Geforce7 - highend */
1064 else if(strstr(gl_info->gl_renderer, "7800") ||
1065 strstr(gl_info->gl_renderer, "7900") ||
1066 strstr(gl_info->gl_renderer, "7950") ||
1067 strstr(gl_info->gl_renderer, "Quadro FX 4") ||
1068 strstr(gl_info->gl_renderer, "Quadro FX 5"))
1070 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7800GT;
1071 vidmem = 256; /* A 7800GT uses 256MB while highend 7900 cards can use 512MB */
1073 /* Geforce7 midend */
1074 else if(strstr(gl_info->gl_renderer, "7600") ||
1075 strstr(gl_info->gl_renderer, "7700")) {
1076 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7600;
1077 vidmem = 256; /* The 7600 uses 256-512MB */
1078 /* Geforce7 lower medium */
1079 } else if(strstr(gl_info->gl_renderer, "7400")) {
1080 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7400;
1081 vidmem = 256; /* The 7400 uses 256-512MB */
1083 /* Geforce7 lowend */
1084 else if(strstr(gl_info->gl_renderer, "7300")) {
1085 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7300;
1086 vidmem = 256; /* Mac Pros with this card have 256 MB */
1088 /* Geforce6 highend */
1089 else if(strstr(gl_info->gl_renderer, "6800"))
1091 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6800;
1092 vidmem = 128; /* The 6800 uses 128-256MB, the 7600 uses 256-512MB */
1094 /* Geforce6 - midend */
1095 else if(strstr(gl_info->gl_renderer, "6600") ||
1096 strstr(gl_info->gl_renderer, "6610") ||
1097 strstr(gl_info->gl_renderer, "6700"))
1099 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6600GT;
1100 vidmem = 128; /* A 6600GT has 128-256MB */
1102 /* Geforce6/7 lowend */
1103 else {
1104 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
1105 vidmem = 64; /* */
1107 } else if(WINE_D3D9_CAPABLE(gl_info)) {
1108 /* GeforceFX - highend */
1109 if (strstr(gl_info->gl_renderer, "5800") ||
1110 strstr(gl_info->gl_renderer, "5900") ||
1111 strstr(gl_info->gl_renderer, "5950") ||
1112 strstr(gl_info->gl_renderer, "Quadro FX"))
1114 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5800;
1115 vidmem = 256; /* 5800-5900 cards use 256MB */
1117 /* GeforceFX - midend */
1118 else if(strstr(gl_info->gl_renderer, "5600") ||
1119 strstr(gl_info->gl_renderer, "5650") ||
1120 strstr(gl_info->gl_renderer, "5700") ||
1121 strstr(gl_info->gl_renderer, "5750"))
1123 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1124 vidmem = 128; /* A 5600 uses 128-256MB */
1126 /* GeforceFX - lowend */
1127 else {
1128 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1129 vidmem = 64; /* Normal FX5200 cards use 64-256MB; laptop (non-standard) can have less */
1131 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1132 if (strstr(gl_info->gl_renderer, "GeForce4 Ti") || strstr(gl_info->gl_renderer, "Quadro4")) {
1133 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1134 vidmem = 64; /* Geforce4 Ti cards have 64-128MB */
1136 else {
1137 gl_info->gl_card = CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1138 vidmem = 64; /* Geforce3 cards have 64-128MB */
1140 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1141 if (strstr(gl_info->gl_renderer, "GeForce4 MX")) {
1142 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1143 vidmem = 64; /* Most Geforce4MX GPUs have at least 64MB of memory, some early models had 32MB but most have 64MB or even 128MB */
1145 else if(strstr(gl_info->gl_renderer, "GeForce2 MX") || strstr(gl_info->gl_renderer, "Quadro2 MXR")) {
1146 gl_info->gl_card = CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1147 vidmem = 32; /* Geforce2MX GPUs have 32-64MB of video memory */
1149 else if(strstr(gl_info->gl_renderer, "GeForce2") || strstr(gl_info->gl_renderer, "Quadro2")) {
1150 gl_info->gl_card = CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1151 vidmem = 32; /* Geforce2 GPUs have 32-64MB of video memory */
1153 else {
1154 gl_info->gl_card = CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1155 vidmem = 32; /* Most Geforce1 cards have 32MB, there are also some rare 16 and 64MB (Dell) models */
1157 } else {
1158 if (strstr(gl_info->gl_renderer, "TNT2")) {
1159 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1160 vidmem = 32; /* Most TNT2 boards have 32MB, though there are 16MB boards too */
1162 else {
1163 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1164 vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
1167 break;
1168 case VENDOR_ATI:
1169 if(WINE_D3D9_CAPABLE(gl_info)) {
1170 /* Radeon R6xx HD2900 - highend */
1171 if (strstr(gl_info->gl_renderer, "HD 2900")) {
1172 gl_info->gl_card = CARD_ATI_RADEON_HD2900;
1173 vidmem = 512; /* HD2900 uses 512-1024MB */
1175 /* Radeon R6xx HD2600- midend */
1176 else if (strstr(gl_info->gl_renderer, "HD 2600")) {
1177 gl_info->gl_card = CARD_ATI_RADEON_HD2600;
1178 vidmem = 256; /* HD2600 uses 256-512MB */
1180 /* Radeon R6xx HD2300/HD2400 - lowend */
1181 else if (strstr(gl_info->gl_renderer, "HD 2300") ||
1182 strstr(gl_info->gl_renderer, "HD 2400"))
1184 gl_info->gl_card = CARD_ATI_RADEON_HD2300;
1185 vidmem = 128; /* HD2300 uses at least 128MB, HD2400 uses 256MB */
1187 /* Radeon R5xx */
1188 else if (strstr(gl_info->gl_renderer, "X1600") ||
1189 strstr(gl_info->gl_renderer, "X1650") ||
1190 strstr(gl_info->gl_renderer, "X1800") ||
1191 strstr(gl_info->gl_renderer, "X1900") ||
1192 strstr(gl_info->gl_renderer, "X1950"))
1194 gl_info->gl_card = CARD_ATI_RADEON_X1600;
1195 vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
1197 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
1198 else if(strstr(gl_info->gl_renderer, "X700") ||
1199 strstr(gl_info->gl_renderer, "X800") ||
1200 strstr(gl_info->gl_renderer, "X850") ||
1201 strstr(gl_info->gl_renderer, "X1300") ||
1202 strstr(gl_info->gl_renderer, "X1400") ||
1203 strstr(gl_info->gl_renderer, "X1450") ||
1204 strstr(gl_info->gl_renderer, "X1550"))
1206 gl_info->gl_card = CARD_ATI_RADEON_X700;
1207 vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
1209 /* Radeon R3xx */
1210 else {
1211 gl_info->gl_card = CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
1212 vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
1214 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1215 gl_info->gl_card = CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
1216 vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
1217 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1218 gl_info->gl_card = CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
1219 vidmem = 32; /* There are models with up to 64MB */
1220 } else {
1221 gl_info->gl_card = CARD_ATI_RAGE_128PRO;
1222 vidmem = 16; /* There are 16-32MB models */
1224 break;
1225 case VENDOR_INTEL:
1226 if (strstr(gl_info->gl_renderer, "GMA 950")) {
1227 /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */
1228 gl_info->gl_card = CARD_INTEL_I945GM;
1229 vidmem = 64;
1230 } else if (strstr(gl_info->gl_renderer, "915GM")) {
1231 gl_info->gl_card = CARD_INTEL_I915GM;
1232 } else if (strstr(gl_info->gl_renderer, "915G")) {
1233 gl_info->gl_card = CARD_INTEL_I915G;
1234 } else if (strstr(gl_info->gl_renderer, "865G")) {
1235 gl_info->gl_card = CARD_INTEL_I865G;
1236 } else if (strstr(gl_info->gl_renderer, "855G")) {
1237 gl_info->gl_card = CARD_INTEL_I855G;
1238 } else if (strstr(gl_info->gl_renderer, "830G")) {
1239 gl_info->gl_card = CARD_INTEL_I830G;
1240 } else {
1241 gl_info->gl_card = CARD_INTEL_I915G;
1243 break;
1244 case VENDOR_MESA:
1245 case VENDOR_WINE:
1246 default:
1247 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice
1248 * for Nvidia was because the hardware and drivers they make are of good quality. This makes
1249 * them a good generic choice.
1251 gl_info->gl_vendor = VENDOR_NVIDIA;
1252 if(WINE_D3D9_CAPABLE(gl_info))
1253 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1254 else if(WINE_D3D8_CAPABLE(gl_info))
1255 gl_info->gl_card = CARD_NVIDIA_GEFORCE3;
1256 else if(WINE_D3D7_CAPABLE(gl_info))
1257 gl_info->gl_card = CARD_NVIDIA_GEFORCE;
1258 else if(WINE_D3D6_CAPABLE(gl_info))
1259 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT;
1260 else
1261 gl_info->gl_card = CARD_NVIDIA_RIVA_128;
1263 TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card);
1265 /* If we have an estimate use it, else default to 64MB; */
1266 if(vidmem)
1267 gl_info->vidmem = vidmem*1024*1024; /* convert from MBs to bytes */
1268 else
1269 gl_info->vidmem = WINE_DEFAULT_VIDMEM;
1271 /* Load all the lookup tables
1272 TODO: It may be a good idea to make minLookup and maxLookup const and populate them in wined3d_private.h where they are declared */
1273 minLookup[WINELOOKUP_WARPPARAM] = WINED3DTADDRESS_WRAP;
1274 maxLookup[WINELOOKUP_WARPPARAM] = WINED3DTADDRESS_MIRRORONCE;
1276 minLookup[WINELOOKUP_MAGFILTER] = WINED3DTEXF_NONE;
1277 maxLookup[WINELOOKUP_MAGFILTER] = WINED3DTEXF_ANISOTROPIC;
1280 for (i = 0; i < MAX_LOOKUPS; i++) {
1281 stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
1284 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
1285 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
1286 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1287 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1288 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1289 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1290 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
1291 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
1292 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
1293 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
1295 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_NONE - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
1296 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_POINT - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
1297 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_LINEAR - minLookup[WINELOOKUP_MAGFILTER]] = GL_LINEAR;
1298 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_ANISOTROPIC - minLookup[WINELOOKUP_MAGFILTER]] =
1299 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR : GL_NEAREST;
1302 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_NONE] = GL_LINEAR;
1303 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_POINT] = GL_LINEAR;
1304 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_LINEAR] = GL_LINEAR;
1305 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_NONE] = GL_NEAREST;
1306 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_POINT] = GL_NEAREST_MIPMAP_NEAREST;
1307 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_LINEAR] = GL_NEAREST_MIPMAP_LINEAR;
1308 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_NONE] = GL_LINEAR;
1309 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_POINT] = GL_LINEAR_MIPMAP_NEAREST;
1310 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_LINEAR] = GL_LINEAR_MIPMAP_LINEAR;
1311 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_NONE] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ?
1312 GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1313 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_POINT] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR;
1314 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_LINEAR] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1316 /* TODO: config lookups */
1318 /* Make sure there's an active HDC else the WGL extensions will fail */
1319 hdc = pwglGetCurrentDC();
1320 if (hdc) {
1321 WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc));
1322 TRACE_(d3d_caps)("WGL_Extensions reported:\n");
1324 if (NULL == WGL_Extensions) {
1325 ERR(" WGL_Extensions returns NULL\n");
1326 } else {
1327 while (*WGL_Extensions != 0x00) {
1328 const char *Start;
1329 char ThisExtn[256];
1330 size_t len;
1332 while (isspace(*WGL_Extensions)) WGL_Extensions++;
1333 Start = WGL_Extensions;
1334 while (!isspace(*WGL_Extensions) && *WGL_Extensions != 0x00) {
1335 WGL_Extensions++;
1338 len = WGL_Extensions - Start;
1339 if (len == 0 || len >= sizeof(ThisExtn))
1340 continue;
1342 memcpy(ThisExtn, Start, len);
1343 ThisExtn[len] = '\0';
1344 TRACE_(d3d_caps)("- %s\n", ThisExtn);
1346 if (!strcmp(ThisExtn, "WGL_ARB_pbuffer")) {
1347 gl_info->supported[WGL_ARB_PBUFFER] = TRUE;
1348 TRACE_(d3d_caps)("FOUND: WGL_ARB_pbuffer support\n");
1353 LEAVE_GL();
1355 return return_value;
1357 #undef GLINFO_LOCATION
1359 /**********************************************************
1360 * IWineD3D implementation follows
1361 **********************************************************/
1363 static UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
1364 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1366 TRACE_(d3d_caps)("(%p): Reporting %d adapters\n", This, numAdapters);
1367 return numAdapters;
1370 static HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
1371 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1372 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
1373 return WINED3D_OK;
1376 static HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
1377 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1379 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
1380 return NULL;
1383 TRACE_(d3d_caps)("(%p)->(%d)\n", This, Adapter);
1384 return MonitorFromPoint(Adapters[Adapter].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
1387 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
1388 of the same bpp but different resolutions */
1390 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1391 static UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
1392 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1393 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
1395 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1396 return 0;
1399 /* TODO: Store modes per adapter and read it from the adapter structure */
1400 if (Adapter == 0) { /* Display */
1401 int i = 0;
1402 int j = 0;
1404 if (!DEBUG_SINGLE_MODE) {
1405 DEVMODEW DevModeW;
1407 ZeroMemory(&DevModeW, sizeof(DevModeW));
1408 DevModeW.dmSize = sizeof(DevModeW);
1409 while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
1410 j++;
1411 switch (Format)
1413 case WINED3DFMT_UNKNOWN:
1414 /* This is for D3D8, do not enumerate P8 here */
1415 if (DevModeW.dmBitsPerPel == 32 ||
1416 DevModeW.dmBitsPerPel == 16) i++;
1417 break;
1418 case WINED3DFMT_X8R8G8B8:
1419 if (DevModeW.dmBitsPerPel == 32) i++;
1420 break;
1421 case WINED3DFMT_R5G6B5:
1422 if (DevModeW.dmBitsPerPel == 16) i++;
1423 break;
1424 case WINED3DFMT_P8:
1425 if (DevModeW.dmBitsPerPel == 8) i++;
1426 break;
1427 default:
1428 /* Skip other modes as they do not match the requested format */
1429 break;
1432 } else {
1433 i = 1;
1434 j = 1;
1437 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
1438 return i;
1439 } else {
1440 FIXME_(d3d_caps)("Adapter not primary display\n");
1442 return 0;
1445 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1446 static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, WINED3DDISPLAYMODE* pMode) {
1447 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1448 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
1450 /* Validate the parameters as much as possible */
1451 if (NULL == pMode ||
1452 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
1453 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
1454 return WINED3DERR_INVALIDCALL;
1457 /* TODO: Store modes per adapter and read it from the adapter structure */
1458 if (Adapter == 0 && !DEBUG_SINGLE_MODE) { /* Display */
1459 DEVMODEW DevModeW;
1460 int ModeIdx = 0;
1461 int i = 0;
1462 int j = 0;
1464 ZeroMemory(&DevModeW, sizeof(DevModeW));
1465 DevModeW.dmSize = sizeof(DevModeW);
1467 /* If we are filtering to a specific format (D3D9), then need to skip
1468 all unrelated modes, but if mode is irrelevant (D3D8), then we can
1469 just count through the ones with valid bit depths */
1470 while ((i<=Mode) && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0)) {
1471 switch (Format)
1473 case WINED3DFMT_UNKNOWN:
1474 /* This is D3D8. Do not enumerate P8 here */
1475 if (DevModeW.dmBitsPerPel == 32 ||
1476 DevModeW.dmBitsPerPel == 16) i++;
1477 break;
1478 case WINED3DFMT_X8R8G8B8:
1479 if (DevModeW.dmBitsPerPel == 32) i++;
1480 break;
1481 case WINED3DFMT_R5G6B5:
1482 if (DevModeW.dmBitsPerPel == 16) i++;
1483 break;
1484 case WINED3DFMT_P8:
1485 if (DevModeW.dmBitsPerPel == 8) i++;
1486 break;
1487 default:
1488 /* Modes that don't match what we support can get an early-out */
1489 TRACE_(d3d_caps)("Searching for %s, returning D3DERR_INVALIDCALL\n", debug_d3dformat(Format));
1490 return WINED3DERR_INVALIDCALL;
1494 if (i == 0) {
1495 TRACE_(d3d_caps)("No modes found for format (%x - %s)\n", Format, debug_d3dformat(Format));
1496 return WINED3DERR_INVALIDCALL;
1498 ModeIdx = j - 1;
1500 /* Now get the display mode via the calculated index */
1501 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0)) {
1502 pMode->Width = DevModeW.dmPelsWidth;
1503 pMode->Height = DevModeW.dmPelsHeight;
1504 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1505 if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
1506 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1508 if (Format == WINED3DFMT_UNKNOWN) {
1509 pMode->Format = pixelformat_for_depth(DevModeW.dmBitsPerPel);
1510 } else {
1511 pMode->Format = Format;
1513 } else {
1514 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
1515 return WINED3DERR_INVALIDCALL;
1518 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
1519 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format),
1520 DevModeW.dmBitsPerPel);
1522 } else if (DEBUG_SINGLE_MODE) {
1523 /* Return one setting of the format requested */
1524 if (Mode > 0) return WINED3DERR_INVALIDCALL;
1525 pMode->Width = 800;
1526 pMode->Height = 600;
1527 pMode->RefreshRate = 60;
1528 pMode->Format = (Format == WINED3DFMT_UNKNOWN) ? WINED3DFMT_X8R8G8B8 : Format;
1529 } else {
1530 FIXME_(d3d_caps)("Adapter not primary display\n");
1533 return WINED3D_OK;
1536 static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, WINED3DDISPLAYMODE* pMode) {
1537 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1538 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
1540 if (NULL == pMode ||
1541 Adapter >= IWineD3D_GetAdapterCount(iface)) {
1542 return WINED3DERR_INVALIDCALL;
1545 if (Adapter == 0) { /* Display */
1546 int bpp = 0;
1547 DEVMODEW DevModeW;
1549 ZeroMemory(&DevModeW, sizeof(DevModeW));
1550 DevModeW.dmSize = sizeof(DevModeW);
1552 EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &DevModeW, 0);
1553 pMode->Width = DevModeW.dmPelsWidth;
1554 pMode->Height = DevModeW.dmPelsHeight;
1555 bpp = DevModeW.dmBitsPerPel;
1556 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1557 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
1559 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1562 pMode->Format = pixelformat_for_depth(bpp);
1563 } else {
1564 FIXME_(d3d_caps)("Adapter not primary display\n");
1567 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
1568 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
1569 return WINED3D_OK;
1572 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
1573 and fields being inserted in the middle, a new structure is used in place */
1574 static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
1575 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
1576 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1578 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %x, pId=%p)\n", This, Adapter, Flags, pIdentifier);
1580 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1581 return WINED3DERR_INVALIDCALL;
1584 /* Return the information requested */
1585 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
1586 strcpy(pIdentifier->Driver, Adapters[Adapter].driver);
1587 strcpy(pIdentifier->Description, Adapters[Adapter].description);
1589 /* Note dx8 doesn't supply a DeviceName */
1590 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
1591 pIdentifier->DriverVersion->u.HighPart = Adapters[Adapter].gl_info.driver_version_hipart;
1592 pIdentifier->DriverVersion->u.LowPart = Adapters[Adapter].gl_info.driver_version;
1593 *(pIdentifier->VendorId) = Adapters[Adapter].gl_info.gl_vendor;
1594 *(pIdentifier->DeviceId) = Adapters[Adapter].gl_info.gl_card;
1595 *(pIdentifier->SubSysId) = 0;
1596 *(pIdentifier->Revision) = 0;
1598 /*FIXME: memcpy(&pIdentifier->DeviceIdentifier, ??, sizeof(??GUID)); */
1599 if (Flags & WINED3DENUM_NO_WHQL_LEVEL) {
1600 *(pIdentifier->WHQLLevel) = 0;
1601 } else {
1602 *(pIdentifier->WHQLLevel) = 1;
1605 return WINED3D_OK;
1608 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const WineD3D_PixelFormat *cfg, WINED3DFORMAT Format) {
1609 short redSize, greenSize, blueSize, alphaSize, colorBits;
1611 if(!cfg)
1612 return FALSE;
1614 if(!getColorBits(Format, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits)) {
1615 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(Format));
1616 return FALSE;
1619 if(cfg->redSize < redSize)
1620 return FALSE;
1622 if(cfg->greenSize < greenSize)
1623 return FALSE;
1625 if(cfg->blueSize < blueSize)
1626 return FALSE;
1628 if(cfg->alphaSize < alphaSize)
1629 return FALSE;
1631 return TRUE;
1634 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const WineD3D_PixelFormat *cfg, WINED3DFORMAT Format) {
1635 short depthSize, stencilSize;
1637 if(!cfg)
1638 return FALSE;
1640 if(!getDepthStencilBits(Format, &depthSize, &stencilSize)) {
1641 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(Format));
1642 return FALSE;
1645 if(cfg->depthSize != depthSize)
1646 return FALSE;
1648 if(cfg->stencilSize != stencilSize)
1649 return FALSE;
1651 return TRUE;
1654 static HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1655 WINED3DFORMAT AdapterFormat,
1656 WINED3DFORMAT RenderTargetFormat,
1657 WINED3DFORMAT DepthStencilFormat) {
1658 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1659 int nCfgs;
1660 WineD3D_PixelFormat *cfgs;
1661 int it;
1663 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
1664 This, Adapter,
1665 DeviceType, debug_d3ddevicetype(DeviceType),
1666 AdapterFormat, debug_d3dformat(AdapterFormat),
1667 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
1668 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
1670 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1671 TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning WINED3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
1672 return WINED3DERR_INVALIDCALL;
1675 cfgs = Adapters[Adapter].cfgs;
1676 nCfgs = Adapters[Adapter].nCfgs;
1677 for (it = 0; it < nCfgs; ++it) {
1678 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], RenderTargetFormat)) {
1679 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&cfgs[it], DepthStencilFormat)) {
1680 TRACE_(d3d_caps)("(%p) : Formats matched\n", This);
1681 return WINED3D_OK;
1685 WARN_(d3d_caps)("unsupported format pair: %s and %s\n", debug_d3dformat(RenderTargetFormat), debug_d3dformat(DepthStencilFormat));
1687 return WINED3DERR_NOTAVAILABLE;
1690 static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1691 WINED3DFORMAT SurfaceFormat,
1692 BOOL Windowed, WINED3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
1694 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1695 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
1696 This,
1697 Adapter,
1698 DeviceType, debug_d3ddevicetype(DeviceType),
1699 SurfaceFormat, debug_d3dformat(SurfaceFormat),
1700 Windowed,
1701 MultiSampleType,
1702 pQualityLevels);
1704 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1705 return WINED3DERR_INVALIDCALL;
1708 /* TODO: Store in Adapter structure */
1709 if (pQualityLevels != NULL) {
1710 static int s_single_shot = 0;
1711 if (!s_single_shot) {
1712 FIXME("Quality levels unsupported at present\n");
1713 s_single_shot = 1;
1715 *pQualityLevels = 1; /* Guess at a value! */
1718 if (WINED3DMULTISAMPLE_NONE == MultiSampleType) return WINED3D_OK;
1719 return WINED3DERR_NOTAVAILABLE;
1722 static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1723 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
1725 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1726 HRESULT hr = WINED3DERR_NOTAVAILABLE;
1727 UINT nmodes;
1729 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
1730 This,
1731 Adapter,
1732 DeviceType, debug_d3ddevicetype(DeviceType),
1733 DisplayFormat, debug_d3dformat(DisplayFormat),
1734 BackBufferFormat, debug_d3dformat(BackBufferFormat),
1735 Windowed);
1737 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1738 WARN_(d3d_caps)("Adapter >= IWineD3D_GetAdapterCount(iface), returning WINED3DERR_INVALIDCALL\n");
1739 return WINED3DERR_INVALIDCALL;
1742 /* The task of this function is to check whether a certain display / backbuffer format
1743 * combination is available on the given adapter. In fullscreen mode microsoft specified
1744 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
1745 * and display format should match exactly.
1746 * In windowed mode format conversion can occur and this depends on the driver. When format
1747 * conversion is done, this function should nevertheless fail and applications need to use
1748 * CheckDeviceFormatConversion.
1749 * At the moment we assume that fullscreen and windowed have the same capabilities */
1751 /* There are only 4 display formats */
1752 if(!((DisplayFormat == WINED3DFMT_R5G6B5) ||
1753 (DisplayFormat == WINED3DFMT_X1R5G5B5) ||
1754 (DisplayFormat == WINED3DFMT_X8R8G8B8) ||
1755 (DisplayFormat == WINED3DFMT_A2R10G10B10)))
1757 TRACE_(d3d_caps)("Format %s unsupported as display format\n", debug_d3dformat(DisplayFormat));
1758 return WINED3DERR_NOTAVAILABLE;
1761 /* If the requested DisplayFormat is not available, don't continue */
1762 nmodes = IWineD3DImpl_GetAdapterModeCount(iface, Adapter, DisplayFormat);
1763 if(!nmodes) {
1764 TRACE_(d3d_caps)("No available modes for display format %s\n", debug_d3dformat(DisplayFormat));
1765 return WINED3DERR_NOTAVAILABLE;
1768 /* Windowed mode allows you to specify WINED3DFMT_UNKNOWN for the backbufferformat, it means 'reuse' the display format for the backbuffer */
1769 if(!Windowed && BackBufferFormat == WINED3DFMT_UNKNOWN) {
1770 TRACE_(d3d_caps)("BackBufferFormat WINED3FMT_UNKNOWN not available in Windowed mode\n");
1771 return WINED3DERR_NOTAVAILABLE;
1774 /* In FULLSCREEN mode R5G6B5 can only be mixed with backbuffer format R5G6B5 */
1775 if( (DisplayFormat == WINED3DFMT_R5G6B5) && (BackBufferFormat != WINED3DFMT_R5G6B5) ) {
1776 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1777 return WINED3DERR_NOTAVAILABLE;
1780 /* In FULLSCREEN mode X1R5G5B5 can only be mixed with backbuffer format *1R5G5B5 */
1781 if( (DisplayFormat == WINED3DFMT_X1R5G5B5) && !((BackBufferFormat == WINED3DFMT_X1R5G5B5) || (BackBufferFormat == WINED3DFMT_A1R5G5B5)) ) {
1782 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1783 return WINED3DERR_NOTAVAILABLE;
1786 /* In FULLSCREEN mode X8R8G8B8 can only be mixed with backbuffer format *8R8G8B8 */
1787 if( (DisplayFormat == WINED3DFMT_X8R8G8B8) && !((BackBufferFormat == WINED3DFMT_X8R8G8B8) || (BackBufferFormat == WINED3DFMT_A8R8G8B8)) ) {
1788 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1789 return WINED3DERR_NOTAVAILABLE;
1792 /* A2R10G10B10 is only allowed in fullscreen mode and it can only be mixed with backbuffer format A2R10G10B10 */
1793 if( (DisplayFormat == WINED3DFMT_A2R10G10B10) && ((BackBufferFormat != WINED3DFMT_A2R10G10B10) || Windowed)) {
1794 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1795 return WINED3DERR_NOTAVAILABLE;
1798 /* Use CheckDeviceFormat to see if the BackBufferFormat is usable with the given DisplayFormat */
1799 hr = IWineD3DImpl_CheckDeviceFormat(iface, Adapter, DeviceType, DisplayFormat, WINED3DUSAGE_RENDERTARGET, WINED3DRTYPE_SURFACE, BackBufferFormat);
1800 if(FAILED(hr))
1801 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1803 return hr;
1806 #define GLINFO_LOCATION Adapters[Adapter].gl_info
1807 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1808 WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat) {
1809 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1810 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%u,%s,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s))\n",
1811 This,
1812 Adapter,
1813 DeviceType, debug_d3ddevicetype(DeviceType),
1814 AdapterFormat, debug_d3dformat(AdapterFormat),
1815 Usage, debug_d3dusage(Usage), debug_d3dusagequery(Usage),
1816 RType, debug_d3dresourcetype(RType),
1817 CheckFormat, debug_d3dformat(CheckFormat));
1819 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1820 return WINED3DERR_INVALIDCALL;
1823 if (Usage & WINED3DUSAGE_QUERY_FILTER) {
1824 switch (CheckFormat) {
1825 /* Filtering not supported */
1826 case WINED3DFMT_R32F:
1827 case WINED3DFMT_A32B32G32R32F:
1828 TRACE_(d3d_caps)("[FAILED]\n");
1829 return WINED3DERR_NOTAVAILABLE;
1830 default:
1831 break;
1835 if (Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
1836 if(!GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
1837 TRACE_(d3d_caps)("[FAILED] - No mipmap generation support\n");
1838 return WINED3DERR_NOTAVAILABLE;
1842 if(RType == WINED3DRTYPE_VOLUMETEXTURE) {
1843 if(!GL_SUPPORT(EXT_TEXTURE3D)) {
1844 TRACE_(d3d_caps)("[FAILED] - No volume texture support\n");
1845 return WINED3DERR_NOTAVAILABLE;
1847 /* Filter formats that need conversion; For one part, this conversion is unimplemented,
1848 * and volume textures are huge, so it would be a big performance hit. Unless we hit an
1849 * app needing one of those formats, don't advertize them to avoid leading apps into
1850 * temptation. The windows drivers don't support most of those formats on volumes anyway,
1851 * except of R32F.
1853 switch(CheckFormat) {
1854 case WINED3DFMT_P8:
1855 case WINED3DFMT_A4L4:
1856 case WINED3DFMT_R32F:
1857 case WINED3DFMT_R16F:
1858 case WINED3DFMT_X8L8V8U8:
1859 case WINED3DFMT_L6V5U5:
1860 case WINED3DFMT_G16R16:
1861 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
1862 return WINED3DERR_NOTAVAILABLE;
1864 case WINED3DFMT_Q8W8V8U8:
1865 case WINED3DFMT_V16U16:
1866 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
1867 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
1868 return WINED3DERR_NOTAVAILABLE;
1870 break;
1872 case WINED3DFMT_V8U8:
1873 if(!GL_SUPPORT(NV_TEXTURE_SHADER) || !GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
1874 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
1875 return WINED3DERR_NOTAVAILABLE;
1877 break;
1879 case WINED3DFMT_DXT1:
1880 case WINED3DFMT_DXT2:
1881 case WINED3DFMT_DXT3:
1882 case WINED3DFMT_DXT4:
1883 case WINED3DFMT_DXT5:
1884 /* The GL_EXT_texture_compression_s3tc spec requires that loading an s3tc
1885 * compressed texture results in an error. While the D3D refrast does
1886 * support s3tc volumes, at least the nvidia windows driver does not, so
1887 * we're free not to support this format.
1889 TRACE_(d3d_caps)("[FAILED] - DXTn does not support 3D textures\n");
1890 return WINED3DERR_NOTAVAILABLE;
1892 default:
1893 /* Do nothing, continue with checking the format below */
1894 break;
1897 /* TODO: Check support against more of the WINED3DUSAGE_QUERY_* constants */
1898 if (Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
1899 if (!GL_LIMITS(vertex_samplers)) {
1900 TRACE_(d3d_caps)("[FAILED]\n");
1901 return WINED3DERR_NOTAVAILABLE;
1904 switch (CheckFormat) {
1905 case WINED3DFMT_A32B32G32R32F:
1906 if (!GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
1907 TRACE_(d3d_caps)("[FAILED]\n");
1908 return WINED3DERR_NOTAVAILABLE;
1910 TRACE_(d3d_caps)("[OK]\n");
1911 return WINED3D_OK;
1913 default:
1914 TRACE_(d3d_caps)("[FAILED]\n");
1915 return WINED3DERR_NOTAVAILABLE;
1919 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
1920 switch (CheckFormat) {
1921 /* In theory we could do all formats, just fetch them accordingly should the buffer be locked.
1922 * Windows supports only those 3, and enumerating the other formats confuses applications
1924 case WINED3DFMT_D24S8:
1925 case WINED3DFMT_D24X8:
1926 case WINED3DFMT_D16:
1927 TRACE_(d3d_caps)("[OK]\n");
1928 return WINED3D_OK;
1929 case WINED3DFMT_D16_LOCKABLE:
1930 case WINED3DFMT_D24FS8:
1931 case WINED3DFMT_D32F_LOCKABLE:
1932 case WINED3DFMT_D24X4S4:
1933 case WINED3DFMT_D15S1:
1934 case WINED3DFMT_D32:
1935 TRACE_(d3d_caps)("[FAILED]. Disabled because not enumerated on windows\n");
1936 return WINED3DERR_NOTAVAILABLE;
1937 default:
1938 TRACE_(d3d_caps)("[FAILED]\n");
1939 return WINED3DERR_NOTAVAILABLE;
1941 } else if(Usage & WINED3DUSAGE_RENDERTARGET) {
1942 switch (CheckFormat) {
1943 case WINED3DFMT_R8G8B8:
1944 case WINED3DFMT_A8R8G8B8:
1945 case WINED3DFMT_X8R8G8B8:
1946 case WINED3DFMT_R5G6B5:
1947 case WINED3DFMT_X1R5G5B5:
1948 case WINED3DFMT_A1R5G5B5:
1949 case WINED3DFMT_A4R4G4B4:
1950 case WINED3DFMT_R3G3B2:
1951 case WINED3DFMT_X4R4G4B4:
1952 case WINED3DFMT_A8B8G8R8:
1953 case WINED3DFMT_X8B8G8R8:
1954 case WINED3DFMT_P8:
1955 case WINED3DFMT_G16R16:
1956 TRACE_(d3d_caps)("[OK]\n");
1957 return WINED3D_OK;
1958 case WINED3DFMT_R16F:
1959 case WINED3DFMT_A16B16G16R16F:
1960 if (!GL_SUPPORT(ARB_HALF_FLOAT_PIXEL) || !GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
1961 TRACE_(d3d_caps)("[FAILED]\n");
1962 return WINED3DERR_NOTAVAILABLE;
1964 TRACE_(d3d_caps)("[OK]\n");
1965 return WINED3D_OK;
1966 case WINED3DFMT_A32B32G32R32F:
1967 if (!GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
1968 TRACE_(d3d_caps)("[FAILED]\n");
1969 return WINED3DERR_NOTAVAILABLE;
1971 TRACE_(d3d_caps)("[OK]\n");
1972 return WINED3D_OK;
1973 default:
1974 TRACE_(d3d_caps)("[FAILED]\n");
1975 return WINED3DERR_NOTAVAILABLE;
1977 } else if(Usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP) {
1978 if(GL_SUPPORT(NV_REGISTER_COMBINERS) && GL_SUPPORT(NV_TEXTURE_SHADER2)) {
1979 switch (CheckFormat) {
1980 case WINED3DFMT_V8U8:
1981 TRACE_(d3d_caps)("[OK]\n");
1982 return WINED3D_OK;
1983 /* TODO: Other bump map formats */
1984 default:
1985 TRACE_(d3d_caps)("[FAILED]\n");
1986 return WINED3DERR_NOTAVAILABLE;
1989 if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
1990 switch (CheckFormat) {
1991 case WINED3DFMT_V8U8:
1992 TRACE_(d3d_caps)("[OK]\n");
1993 return WINED3D_OK;
1994 default:
1995 TRACE_(d3d_caps)("[FAILED]\n");
1996 return WINED3DERR_NOTAVAILABLE;
1999 TRACE_(d3d_caps)("[FAILED]\n");
2000 return WINED3DERR_NOTAVAILABLE;
2003 /* Check for supported sRGB formats (Texture loading and framebuffer) */
2004 if (Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2005 if(!GL_SUPPORT(EXT_TEXTURE_SRGB)) {
2006 TRACE_(d3d_caps)("[FAILED] GL_EXT_texture_sRGB not supported\n");
2009 switch (CheckFormat) {
2010 case WINED3DFMT_A8R8G8B8:
2011 case WINED3DFMT_X8R8G8B8:
2012 case WINED3DFMT_A4R4G4B4:
2013 case WINED3DFMT_L8:
2014 case WINED3DFMT_A8L8:
2015 case WINED3DFMT_DXT1:
2016 case WINED3DFMT_DXT2:
2017 case WINED3DFMT_DXT3:
2018 case WINED3DFMT_DXT4:
2019 case WINED3DFMT_DXT5:
2020 TRACE_(d3d_caps)("[OK]\n");
2021 break; /* Continue with checking other flags */
2023 default:
2024 TRACE_(d3d_caps)("[FAILED] Gamma texture format %s not supported.\n", debug_d3dformat(CheckFormat));
2025 return WINED3DERR_NOTAVAILABLE;
2029 /* This format is nothing special and it is supported perfectly.
2030 * However, ati and nvidia driver on windows do not mark this format as
2031 * supported (tested with the dxCapsViewer) and pretending to
2032 * support this format uncovers a bug in Battlefield 1942 (fonts are missing)
2033 * So do the same as Windows drivers and pretend not to support it on dx8 and 9
2034 * Enable it on dx7. It will need additional checking on dx10 when we support it.
2036 if(This->dxVersion > 7 && CheckFormat == WINED3DFMT_R8G8B8) {
2037 TRACE_(d3d_caps)("[FAILED]\n");
2038 return WINED3DERR_NOTAVAILABLE;
2041 switch (CheckFormat) {
2043 /*****
2044 * supported: RGB(A) formats
2046 case WINED3DFMT_R8G8B8: /* Enable for dx7, blacklisted for 8 and 9 above */
2047 case WINED3DFMT_A8R8G8B8:
2048 case WINED3DFMT_X8R8G8B8:
2049 case WINED3DFMT_R5G6B5:
2050 case WINED3DFMT_X1R5G5B5:
2051 case WINED3DFMT_A1R5G5B5:
2052 case WINED3DFMT_A4R4G4B4:
2053 case WINED3DFMT_R3G3B2:
2054 case WINED3DFMT_A8:
2055 case WINED3DFMT_X4R4G4B4:
2056 case WINED3DFMT_A8B8G8R8:
2057 case WINED3DFMT_X8B8G8R8:
2058 case WINED3DFMT_A2R10G10B10:
2059 case WINED3DFMT_A2B10G10R10:
2060 case WINED3DFMT_G16R16:
2061 TRACE_(d3d_caps)("[OK]\n");
2062 return WINED3D_OK;
2064 /*****
2065 * supported: Palettized
2067 case WINED3DFMT_P8:
2068 TRACE_(d3d_caps)("[OK]\n");
2069 return WINED3D_OK;
2071 /*****
2072 * Supported: (Alpha)-Luminance
2074 case WINED3DFMT_L8:
2075 case WINED3DFMT_A8L8:
2076 case WINED3DFMT_A4L4:
2077 TRACE_(d3d_caps)("[OK]\n");
2078 return WINED3D_OK;
2080 /*****
2081 * Not supported everywhere(depends on GL_ATI_envmap_bumpmap or
2082 * GL_NV_texture_shader), but advertized to make apps happy.
2083 * Enable some because games often fail when they are not available
2084 * and are still playable even without bump mapping
2086 case WINED3DFMT_V8U8:
2087 case WINED3DFMT_V16U16:
2088 case WINED3DFMT_L6V5U5:
2089 case WINED3DFMT_X8L8V8U8:
2090 case WINED3DFMT_Q8W8V8U8:
2091 WARN_(d3d_caps)("[Not supported, but pretended to do]\n");
2092 return WINED3D_OK;
2094 /* Those are not advertized by the nvidia windows driver, and not
2095 * supported natively by GL_NV_texture_shader or GL_ATI_envmap_bumpmap.
2096 * WINED3DFMT_A2W10V10U10 could be loaded into shaders using the unsigned
2097 * ARGB format if needed
2099 case WINED3DFMT_W11V11U10:
2100 case WINED3DFMT_A2W10V10U10:
2101 WARN_(d3d_caps)("[FAILED]\n");
2102 return WINED3DERR_NOTAVAILABLE;
2104 case WINED3DFMT_DXT1:
2105 case WINED3DFMT_DXT2:
2106 case WINED3DFMT_DXT3:
2107 case WINED3DFMT_DXT4:
2108 case WINED3DFMT_DXT5:
2109 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
2110 TRACE_(d3d_caps)("[OK]\n");
2111 return WINED3D_OK;
2112 } else {
2113 TRACE_(d3d_caps)("[FAILED]\n");
2114 return WINED3DERR_NOTAVAILABLE;
2118 /*****
2119 * Odd formats - not supported
2121 case WINED3DFMT_VERTEXDATA:
2122 case WINED3DFMT_INDEX16:
2123 case WINED3DFMT_INDEX32:
2124 case WINED3DFMT_Q16W16V16U16:
2125 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2126 return WINED3DERR_NOTAVAILABLE;
2128 /*****
2129 * WINED3DFMT_CxV8U8: Not supported right now
2131 case WINED3DFMT_CxV8U8:
2132 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2133 return WINED3DERR_NOTAVAILABLE;
2135 /* Not supported */
2136 case WINED3DFMT_A16B16G16R16:
2137 case WINED3DFMT_A8R3G3B2:
2138 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2139 return WINED3DERR_NOTAVAILABLE;
2141 /* Floating point formats */
2142 case WINED3DFMT_R16F:
2143 case WINED3DFMT_A16B16G16R16F:
2144 if(GL_SUPPORT(ARB_HALF_FLOAT_PIXEL)) {
2145 TRACE_(d3d_caps)("[OK]\n");
2146 return WINED3D_OK;
2147 } else {
2148 TRACE_(d3d_caps)("[FAILED]\n");
2149 return WINED3DERR_NOTAVAILABLE;
2151 case WINED3DFMT_R32F:
2152 case WINED3DFMT_A32B32G32R32F:
2153 if (GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2154 TRACE_(d3d_caps)("[OK]\n");
2155 return WINED3D_OK;
2156 } else {
2157 TRACE_(d3d_caps)("[FAILED]\n");
2158 return WINED3DERR_NOTAVAILABLE;
2161 case WINED3DFMT_G16R16F:
2162 case WINED3DFMT_G32R32F:
2163 TRACE_(d3d_caps)("[FAILED]\n");
2164 return WINED3DERR_NOTAVAILABLE;
2166 /* ATI instancing hack: Although ATI cards do not support Shader Model 3.0, they support
2167 * instancing. To query if the card supports instancing CheckDeviceFormat with the special format
2168 * MAKEFOURCC('I','N','S','T') is used. Should a (broken) app check for this provide a proper return value.
2169 * We can do instancing with all shader versions, but we need vertex shaders.
2171 * Additionally applications have to set the D3DRS_POINTSIZE render state to MAKEFOURCC('I','N','S','T') once
2172 * to enable instancing. WineD3D doesn't need that and just ignores it.
2174 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows.
2176 case WINEMAKEFOURCC('I','N','S','T'):
2177 TRACE("ATI Instancing check hack\n");
2178 if(GL_SUPPORT(ARB_VERTEX_PROGRAM) || GL_SUPPORT(ARB_VERTEX_SHADER)) {
2179 TRACE_(d3d_caps)("[OK]\n");
2180 return WINED3D_OK;
2181 } else {
2182 TRACE_(d3d_caps)("[FAILED]\n");
2183 return WINED3DERR_NOTAVAILABLE;
2186 default:
2187 break;
2190 TRACE_(d3d_caps)("[FAILED]\n");
2191 return WINED3DERR_NOTAVAILABLE;
2194 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2195 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
2196 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2198 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))\n",
2199 This,
2200 Adapter,
2201 DeviceType, debug_d3ddevicetype(DeviceType),
2202 SourceFormat, debug_d3dformat(SourceFormat),
2203 TargetFormat, debug_d3dformat(TargetFormat));
2204 return WINED3D_OK;
2207 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
2208 subset of a D3DCAPS9 structure. However, it has to come via a void *
2209 as the d3d8 interface cannot import the d3d9 header */
2210 static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
2212 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2213 int vs_selected_mode;
2214 int ps_selected_mode;
2216 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
2218 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2219 return WINED3DERR_INVALIDCALL;
2222 select_shader_mode(&Adapters[Adapter].gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
2224 /* This function should *not* be modifying GL caps
2225 * TODO: move the functionality where it belongs */
2226 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &Adapters[Adapter].gl_info);
2228 /* ------------------------------------------------
2229 The following fields apply to both d3d8 and d3d9
2230 ------------------------------------------------ */
2231 *pCaps->DeviceType = (DeviceType == WINED3DDEVTYPE_HAL) ? WINED3DDEVTYPE_HAL : WINED3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
2232 *pCaps->AdapterOrdinal = Adapter;
2234 *pCaps->Caps = 0;
2235 *pCaps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
2236 WINED3DCAPS2_FULLSCREENGAMMA |
2237 WINED3DCAPS2_DYNAMICTEXTURES;
2238 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2239 *pCaps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
2241 *pCaps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD;
2242 *pCaps->PresentationIntervals = WINED3DPRESENT_INTERVAL_IMMEDIATE |
2243 WINED3DPRESENT_INTERVAL_ONE;
2245 *pCaps->CursorCaps = WINED3DCURSORCAPS_COLOR |
2246 WINED3DCURSORCAPS_LOWRES;
2248 *pCaps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
2249 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
2250 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
2251 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
2252 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
2253 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
2254 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
2255 WINED3DDEVCAPS_PUREDEVICE |
2256 WINED3DDEVCAPS_HWRASTERIZATION |
2257 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
2258 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
2259 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
2260 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
2261 WINED3DDEVCAPS_DRAWPRIMITIVES2EX |
2262 WINED3DDEVCAPS_RTPATCHES;
2264 *pCaps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
2265 WINED3DPMISCCAPS_CULLCCW |
2266 WINED3DPMISCCAPS_CULLCW |
2267 WINED3DPMISCCAPS_COLORWRITEENABLE |
2268 WINED3DPMISCCAPS_CLIPTLVERTS |
2269 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
2270 WINED3DPMISCCAPS_MASKZ |
2271 WINED3DPMISCCAPS_BLENDOP;
2272 /* TODO:
2273 WINED3DPMISCCAPS_NULLREFERENCE
2274 WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS
2275 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
2276 WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
2277 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING
2278 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
2280 if(GL_SUPPORT(EXT_BLEND_EQUATION_SEPARATE) && GL_SUPPORT(EXT_BLEND_FUNC_SEPARATE))
2281 *pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
2283 /* The caps below can be supported but aren't handled yet in utils.c 'd3dta_to_combiner_input', disable them until support is fixed */
2284 #if 0
2285 if (GL_SUPPORT(NV_REGISTER_COMBINERS))
2286 *pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_TSSARGTEMP;
2287 if (GL_SUPPORT(NV_REGISTER_COMBINERS2))
2288 *pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_PERSTAGECONSTANT;
2289 #endif
2291 *pCaps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
2292 WINED3DPRASTERCAPS_PAT |
2293 WINED3DPRASTERCAPS_WFOG |
2294 WINED3DPRASTERCAPS_ZFOG |
2295 WINED3DPRASTERCAPS_FOGVERTEX |
2296 WINED3DPRASTERCAPS_FOGTABLE |
2297 WINED3DPRASTERCAPS_STIPPLE |
2298 WINED3DPRASTERCAPS_SUBPIXEL |
2299 WINED3DPRASTERCAPS_ZTEST |
2300 WINED3DPRASTERCAPS_SCISSORTEST |
2301 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
2302 WINED3DPRASTERCAPS_DEPTHBIAS;
2304 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2305 *pCaps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY |
2306 WINED3DPRASTERCAPS_ZBIAS |
2307 WINED3DPRASTERCAPS_MIPMAPLODBIAS;
2309 if(GL_SUPPORT(NV_FOG_DISTANCE)) {
2310 *pCaps->RasterCaps |= WINED3DPRASTERCAPS_FOGRANGE;
2312 /* FIXME Add:
2313 WINED3DPRASTERCAPS_COLORPERSPECTIVE
2314 WINED3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
2315 WINED3DPRASTERCAPS_ANTIALIASEDGES
2316 WINED3DPRASTERCAPS_ZBUFFERLESSHSR
2317 WINED3DPRASTERCAPS_WBUFFER */
2319 *pCaps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
2320 WINED3DPCMPCAPS_EQUAL |
2321 WINED3DPCMPCAPS_GREATER |
2322 WINED3DPCMPCAPS_GREATEREQUAL |
2323 WINED3DPCMPCAPS_LESS |
2324 WINED3DPCMPCAPS_LESSEQUAL |
2325 WINED3DPCMPCAPS_NEVER |
2326 WINED3DPCMPCAPS_NOTEQUAL;
2328 *pCaps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
2329 WINED3DPBLENDCAPS_BOTHSRCALPHA |
2330 WINED3DPBLENDCAPS_DESTALPHA |
2331 WINED3DPBLENDCAPS_DESTCOLOR |
2332 WINED3DPBLENDCAPS_INVDESTALPHA |
2333 WINED3DPBLENDCAPS_INVDESTCOLOR |
2334 WINED3DPBLENDCAPS_INVSRCALPHA |
2335 WINED3DPBLENDCAPS_INVSRCCOLOR |
2336 WINED3DPBLENDCAPS_ONE |
2337 WINED3DPBLENDCAPS_SRCALPHA |
2338 WINED3DPBLENDCAPS_SRCALPHASAT |
2339 WINED3DPBLENDCAPS_SRCCOLOR |
2340 WINED3DPBLENDCAPS_ZERO;
2342 *pCaps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
2343 WINED3DPBLENDCAPS_DESTCOLOR |
2344 WINED3DPBLENDCAPS_INVDESTALPHA |
2345 WINED3DPBLENDCAPS_INVDESTCOLOR |
2346 WINED3DPBLENDCAPS_INVSRCALPHA |
2347 WINED3DPBLENDCAPS_INVSRCCOLOR |
2348 WINED3DPBLENDCAPS_ONE |
2349 WINED3DPBLENDCAPS_SRCALPHA |
2350 WINED3DPBLENDCAPS_SRCCOLOR |
2351 WINED3DPBLENDCAPS_ZERO;
2352 /* NOTE: WINED3DPBLENDCAPS_SRCALPHASAT is not supported as dest blend factor,
2353 * according to the glBlendFunc manpage
2355 * WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA are
2356 * legacy settings for srcblend only
2359 if( GL_SUPPORT(EXT_BLEND_COLOR)) {
2360 *pCaps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
2361 *pCaps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
2365 *pCaps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
2366 WINED3DPCMPCAPS_EQUAL |
2367 WINED3DPCMPCAPS_GREATER |
2368 WINED3DPCMPCAPS_GREATEREQUAL |
2369 WINED3DPCMPCAPS_LESS |
2370 WINED3DPCMPCAPS_LESSEQUAL |
2371 WINED3DPCMPCAPS_NEVER |
2372 WINED3DPCMPCAPS_NOTEQUAL;
2374 *pCaps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
2375 WINED3DPSHADECAPS_COLORGOURAUDRGB |
2376 WINED3DPSHADECAPS_ALPHAFLATBLEND |
2377 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
2378 WINED3DPSHADECAPS_COLORFLATRGB |
2379 WINED3DPSHADECAPS_FOGFLAT |
2380 WINED3DPSHADECAPS_FOGGOURAUD |
2381 WINED3DPSHADECAPS_SPECULARFLATRGB;
2383 *pCaps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
2384 WINED3DPTEXTURECAPS_ALPHAPALETTE |
2385 WINED3DPTEXTURECAPS_BORDER |
2386 WINED3DPTEXTURECAPS_MIPMAP |
2387 WINED3DPTEXTURECAPS_PROJECTED |
2388 WINED3DPTEXTURECAPS_PERSPECTIVE;
2390 if( !GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
2391 *pCaps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
2392 WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
2395 if( GL_SUPPORT(EXT_TEXTURE3D)) {
2396 *pCaps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP |
2397 WINED3DPTEXTURECAPS_MIPVOLUMEMAP |
2398 WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
2401 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2402 *pCaps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP |
2403 WINED3DPTEXTURECAPS_MIPCUBEMAP |
2404 WINED3DPTEXTURECAPS_CUBEMAP_POW2;
2408 *pCaps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2409 WINED3DPTFILTERCAPS_MAGFPOINT |
2410 WINED3DPTFILTERCAPS_MINFLINEAR |
2411 WINED3DPTFILTERCAPS_MINFPOINT |
2412 WINED3DPTFILTERCAPS_MIPFLINEAR |
2413 WINED3DPTFILTERCAPS_MIPFPOINT |
2414 WINED3DPTFILTERCAPS_LINEAR |
2415 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2416 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2417 WINED3DPTFILTERCAPS_MIPLINEAR |
2418 WINED3DPTFILTERCAPS_MIPNEAREST |
2419 WINED3DPTFILTERCAPS_NEAREST;
2421 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2422 *pCaps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
2423 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
2426 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2427 *pCaps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2428 WINED3DPTFILTERCAPS_MAGFPOINT |
2429 WINED3DPTFILTERCAPS_MINFLINEAR |
2430 WINED3DPTFILTERCAPS_MINFPOINT |
2431 WINED3DPTFILTERCAPS_MIPFLINEAR |
2432 WINED3DPTFILTERCAPS_MIPFPOINT |
2433 WINED3DPTFILTERCAPS_LINEAR |
2434 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2435 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2436 WINED3DPTFILTERCAPS_MIPLINEAR |
2437 WINED3DPTFILTERCAPS_MIPNEAREST |
2438 WINED3DPTFILTERCAPS_NEAREST;
2440 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2441 *pCaps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
2442 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
2444 } else
2445 *pCaps->CubeTextureFilterCaps = 0;
2447 if (GL_SUPPORT(EXT_TEXTURE3D)) {
2448 *pCaps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2449 WINED3DPTFILTERCAPS_MAGFPOINT |
2450 WINED3DPTFILTERCAPS_MINFLINEAR |
2451 WINED3DPTFILTERCAPS_MINFPOINT |
2452 WINED3DPTFILTERCAPS_MIPFLINEAR |
2453 WINED3DPTFILTERCAPS_MIPFPOINT |
2454 WINED3DPTFILTERCAPS_LINEAR |
2455 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2456 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2457 WINED3DPTFILTERCAPS_MIPLINEAR |
2458 WINED3DPTFILTERCAPS_MIPNEAREST |
2459 WINED3DPTFILTERCAPS_NEAREST;
2460 } else
2461 *pCaps->VolumeTextureFilterCaps = 0;
2463 *pCaps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
2464 WINED3DPTADDRESSCAPS_CLAMP |
2465 WINED3DPTADDRESSCAPS_WRAP;
2467 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
2468 *pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
2470 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
2471 *pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
2473 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
2474 *pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
2477 if (GL_SUPPORT(EXT_TEXTURE3D)) {
2478 *pCaps->VolumeTextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
2479 WINED3DPTADDRESSCAPS_CLAMP |
2480 WINED3DPTADDRESSCAPS_WRAP;
2481 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
2482 *pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
2484 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
2485 *pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
2487 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
2488 *pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
2490 } else
2491 *pCaps->VolumeTextureAddressCaps = 0;
2493 *pCaps->LineCaps = WINED3DLINECAPS_TEXTURE |
2494 WINED3DLINECAPS_ZTEST;
2495 /* FIXME: Add
2496 WINED3DLINECAPS_BLEND
2497 WINED3DLINECAPS_ALPHACMP
2498 WINED3DLINECAPS_FOG */
2500 *pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
2501 *pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
2503 if(GL_SUPPORT(EXT_TEXTURE3D))
2504 *pCaps->MaxVolumeExtent = GL_LIMITS(texture3d_size);
2505 else
2506 *pCaps->MaxVolumeExtent = 0;
2508 *pCaps->MaxTextureRepeat = 32768;
2509 *pCaps->MaxTextureAspectRatio = GL_LIMITS(texture_size);
2510 *pCaps->MaxVertexW = 1.0;
2512 *pCaps->GuardBandLeft = 0;
2513 *pCaps->GuardBandTop = 0;
2514 *pCaps->GuardBandRight = 0;
2515 *pCaps->GuardBandBottom = 0;
2517 *pCaps->ExtentsAdjust = 0;
2519 *pCaps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
2520 WINED3DSTENCILCAPS_INCRSAT |
2521 WINED3DSTENCILCAPS_INVERT |
2522 WINED3DSTENCILCAPS_KEEP |
2523 WINED3DSTENCILCAPS_REPLACE |
2524 WINED3DSTENCILCAPS_ZERO;
2525 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
2526 *pCaps->StencilCaps |= WINED3DSTENCILCAPS_DECR |
2527 WINED3DSTENCILCAPS_INCR;
2529 if ( This->dxVersion > 8 &&
2530 ( GL_SUPPORT(EXT_STENCIL_TWO_SIDE) ||
2531 GL_SUPPORT(ATI_SEPARATE_STENCIL) ) ) {
2532 *pCaps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
2535 *pCaps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
2537 *pCaps->TextureOpCaps = WINED3DTEXOPCAPS_ADD |
2538 WINED3DTEXOPCAPS_ADDSIGNED |
2539 WINED3DTEXOPCAPS_ADDSIGNED2X |
2540 WINED3DTEXOPCAPS_MODULATE |
2541 WINED3DTEXOPCAPS_MODULATE2X |
2542 WINED3DTEXOPCAPS_MODULATE4X |
2543 WINED3DTEXOPCAPS_SELECTARG1 |
2544 WINED3DTEXOPCAPS_SELECTARG2 |
2545 WINED3DTEXOPCAPS_DISABLE;
2547 if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE) ||
2548 GL_SUPPORT(EXT_TEXTURE_ENV_COMBINE) ||
2549 GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
2550 *pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA |
2551 WINED3DTEXOPCAPS_BLENDTEXTUREALPHA |
2552 WINED3DTEXOPCAPS_BLENDFACTORALPHA |
2553 WINED3DTEXOPCAPS_BLENDCURRENTALPHA |
2554 WINED3DTEXOPCAPS_LERP |
2555 WINED3DTEXOPCAPS_SUBTRACT;
2557 if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3) ||
2558 GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
2559 *pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_ADDSMOOTH |
2560 WINED3DTEXOPCAPS_MULTIPLYADD |
2561 WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
2562 WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
2563 WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM;
2565 if (GL_SUPPORT(ARB_TEXTURE_ENV_DOT3))
2566 *pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_DOTPRODUCT3;
2568 if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
2569 *pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR |
2570 WINED3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA;
2573 if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
2574 *pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAP;
2575 } else if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
2576 /* Bump mapping is supported already in NV_TEXTURE_SHADER, but that extension does
2577 * not support 3D textures. This asks for trouble if an app uses both bump mapping
2578 * and 3D textures. It also allows us to keep the code simpler by having texture
2579 * shaders constantly enabled.
2581 *pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAP;
2582 /* TODO: Luminance bump map? */
2584 #if 0
2585 /* FIXME: Add
2586 *pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAPLUMINANCE
2587 WINED3DTEXOPCAPS_PREMODULATE */
2588 #endif
2590 *pCaps->MaxTextureBlendStages = GL_LIMITS(texture_stages);
2591 *pCaps->MaxSimultaneousTextures = GL_LIMITS(textures);
2592 *pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
2593 *pCaps->MaxActiveLights = GL_LIMITS(lights);
2595 *pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
2596 *pCaps->MaxVertexBlendMatrixIndex = 0;
2598 *pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
2599 *pCaps->MaxPointSize = GL_LIMITS(pointsize);
2602 *pCaps->VertexProcessingCaps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
2603 WINED3DVTXPCAPS_MATERIALSOURCE7 |
2604 WINED3DVTXPCAPS_POSITIONALLIGHTS |
2605 WINED3DVTXPCAPS_LOCALVIEWER |
2606 WINED3DVTXPCAPS_VERTEXFOG |
2607 WINED3DVTXPCAPS_TEXGEN;
2608 /* FIXME: Add
2609 D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
2611 *pCaps->MaxPrimitiveCount = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
2612 *pCaps->MaxVertexIndex = 0xFFFFF;
2613 *pCaps->MaxStreams = MAX_STREAMS;
2614 *pCaps->MaxStreamStride = 1024;
2616 if (vs_selected_mode == SHADER_GLSL) {
2617 /* Nvidia Geforce6/7 or Ati R4xx/R5xx cards with GLSL support, support VS 3.0 but older Nvidia/Ati
2618 * models with GLSL support only support 2.0. In case of nvidia we can detect VS 2.0 support using
2619 * vs_nv_version which is based on NV_vertex_program.
2620 * For Ati cards there's no way using glsl (it abstracts the lowlevel info away) and also not
2621 * using ARB_vertex_program. It is safe to assume that when a card supports pixel shader 2.0 it
2622 * supports vertex shader 2.0 too and the way around. We can detect ps2.0 using the maximum number
2623 * of native instructions, so use that here. For more info see the pixel shader versioning code below. */
2624 if((GLINFO_LOCATION.vs_nv_version == VS_VERSION_20) || (GLINFO_LOCATION.ps_arb_max_instructions <= 512))
2625 *pCaps->VertexShaderVersion = WINED3DVS_VERSION(2,0);
2626 else
2627 *pCaps->VertexShaderVersion = WINED3DVS_VERSION(3,0);
2628 TRACE_(d3d_caps)("Hardware vertex shader version %d.%d enabled (GLSL)\n", (*pCaps->VertexShaderVersion >> 8) & 0xff, *pCaps->VertexShaderVersion & 0xff);
2629 } else if (vs_selected_mode == SHADER_ARB) {
2630 *pCaps->VertexShaderVersion = WINED3DVS_VERSION(1,1);
2631 TRACE_(d3d_caps)("Hardware vertex shader version 1.1 enabled (ARB_PROGRAM)\n");
2632 } else {
2633 *pCaps->VertexShaderVersion = 0;
2634 TRACE_(d3d_caps)("Vertex shader functionality not available\n");
2637 *pCaps->MaxVertexShaderConst = GL_LIMITS(vshader_constantsF);
2639 if (ps_selected_mode == SHADER_GLSL) {
2640 /* Older DX9-class videocards (GeforceFX / Radeon >9500/X*00) only support pixel shader 2.0/2.0a/2.0b.
2641 * In OpenGL the extensions related to GLSL abstract lowlevel GL info away which is needed
2642 * to distinguish between 2.0 and 3.0 (and 2.0a/2.0b). In case of Nvidia we use their fragment
2643 * program extensions. On other hardware including ATI GL_ARB_fragment_program offers the info
2644 * in max native instructions. Intel and others also offer the info in this extension but they
2645 * don't support GLSL (at least on Windows).
2647 * PS2.0 requires at least 96 instructions, 2.0a/2.0b go up to 512. Assume that if the number
2648 * of instructions is 512 or less we have to do with ps2.0 hardware.
2649 * NOTE: ps3.0 hardware requires 512 or more instructions but ati and nvidia offer 'enough' (1024 vs 4096) on their most basic ps3.0 hardware.
2651 if((GLINFO_LOCATION.ps_nv_version == PS_VERSION_20) || (GLINFO_LOCATION.ps_arb_max_instructions <= 512))
2652 *pCaps->PixelShaderVersion = WINED3DPS_VERSION(2,0);
2653 else
2654 *pCaps->PixelShaderVersion = WINED3DPS_VERSION(3,0);
2655 /* FIXME: The following line is card dependent. -8.0 to 8.0 is the
2656 * Direct3D minimum requirement.
2658 * Both GL_ARB_fragment_program and GLSL require a "maximum representable magnitude"
2659 * of colors to be 2^10, and 2^32 for other floats. Should we use 1024 here?
2661 * The problem is that the refrast clamps temporary results in the shader to
2662 * [-MaxValue;+MaxValue]. If the card's max value is bigger than the one we advertize here,
2663 * then applications may miss the clamping behavior. On the other hand, if it is smaller,
2664 * the shader will generate incorrect results too. Unfortunately, GL deliberately doesn't
2665 * offer a way to query this.
2667 *pCaps->PixelShader1xMaxValue = 8.0;
2668 TRACE_(d3d_caps)("Hardware pixel shader version %d.%d enabled (GLSL)\n", (*pCaps->PixelShaderVersion >> 8) & 0xff, *pCaps->PixelShaderVersion & 0xff);
2669 } else if (ps_selected_mode == SHADER_ARB) {
2670 *pCaps->PixelShaderVersion = WINED3DPS_VERSION(1,4);
2671 *pCaps->PixelShader1xMaxValue = 8.0;
2672 TRACE_(d3d_caps)("Hardware pixel shader version 1.4 enabled (ARB_PROGRAM)\n");
2673 } else {
2674 *pCaps->PixelShaderVersion = 0;
2675 *pCaps->PixelShader1xMaxValue = 0.0;
2676 TRACE_(d3d_caps)("Pixel shader functionality not available\n");
2679 /* ------------------------------------------------
2680 The following fields apply to d3d9 only
2681 ------------------------------------------------ */
2682 if (This->dxVersion > 8) {
2683 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
2684 *pCaps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET;
2685 /* TODO: VS3.0 needs at least D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET */
2686 *pCaps->MaxNpatchTessellationLevel = 0;
2687 *pCaps->MasterAdapterOrdinal = 0;
2688 *pCaps->AdapterOrdinalInGroup = 0;
2689 *pCaps->NumberOfAdaptersInGroup = 1;
2691 if(*pCaps->VertexShaderVersion >= WINED3DVS_VERSION(2,0)) {
2692 /* OpenGL supports all the formats below, perhaps not always
2693 * without conversion, but it supports them.
2694 * Further GLSL doesn't seem to have an official unsigned type so
2695 * don't advertise it yet as I'm not sure how we handle it.
2696 * We might need to add some clamping in the shader engine to
2697 * support it.
2698 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
2699 *pCaps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
2700 WINED3DDTCAPS_UBYTE4N |
2701 WINED3DDTCAPS_SHORT2N |
2702 WINED3DDTCAPS_SHORT4N;
2703 if (GL_SUPPORT(NV_HALF_FLOAT)) {
2704 *pCaps->DeclTypes |=
2705 WINED3DDTCAPS_FLOAT16_2 |
2706 WINED3DDTCAPS_FLOAT16_4;
2708 } else
2709 *pCaps->DeclTypes = 0;
2711 *pCaps->NumSimultaneousRTs = GL_LIMITS(buffers);
2714 *pCaps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
2715 WINED3DPTFILTERCAPS_MAGFPOINT |
2716 WINED3DPTFILTERCAPS_MINFLINEAR |
2717 WINED3DPTFILTERCAPS_MAGFLINEAR;
2718 *pCaps->VertexTextureFilterCaps = 0;
2720 if(*pCaps->VertexShaderVersion == WINED3DVS_VERSION(3,0)) {
2721 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
2722 use the VS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum VS3.0 value. */
2723 *pCaps->VS20Caps.Caps = WINED3DVS20CAPS_PREDICATION;
2724 *pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
2725 *pCaps->VS20Caps.NumTemps = max(32, GLINFO_LOCATION.vs_arb_max_temps);
2726 *pCaps->VS20Caps.StaticFlowControlDepth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH ; /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
2728 *pCaps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
2729 *pCaps->MaxVertexShader30InstructionSlots = max(512, GLINFO_LOCATION.vs_arb_max_instructions);
2730 } else if(*pCaps->VertexShaderVersion == WINED3DVS_VERSION(2,0)) {
2731 *pCaps->VS20Caps.Caps = 0;
2732 *pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
2733 *pCaps->VS20Caps.NumTemps = max(12, GLINFO_LOCATION.vs_arb_max_temps);
2734 *pCaps->VS20Caps.StaticFlowControlDepth = 1;
2736 *pCaps->MaxVShaderInstructionsExecuted = 65535;
2737 *pCaps->MaxVertexShader30InstructionSlots = 0;
2738 } else { /* VS 1.x */
2739 *pCaps->VS20Caps.Caps = 0;
2740 *pCaps->VS20Caps.DynamicFlowControlDepth = 0;
2741 *pCaps->VS20Caps.NumTemps = 0;
2742 *pCaps->VS20Caps.StaticFlowControlDepth = 0;
2744 *pCaps->MaxVShaderInstructionsExecuted = 0;
2745 *pCaps->MaxVertexShader30InstructionSlots = 0;
2748 if(*pCaps->PixelShaderVersion == WINED3DPS_VERSION(3,0)) {
2749 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
2750 use the PS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum PS 3.0 value. */
2752 /* 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 */
2753 *pCaps->PS20Caps.Caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
2754 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
2755 WINED3DPS20CAPS_PREDICATION |
2756 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
2757 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
2758 *pCaps->PS20Caps.DynamicFlowControlDepth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
2759 *pCaps->PS20Caps.NumTemps = max(32, GLINFO_LOCATION.ps_arb_max_temps);
2760 *pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
2761 *pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
2763 *pCaps->MaxPShaderInstructionsExecuted = 65535;
2764 *pCaps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS, GLINFO_LOCATION.ps_arb_max_instructions);
2765 } else if(*pCaps->PixelShaderVersion == WINED3DPS_VERSION(2,0)) {
2766 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
2767 *pCaps->PS20Caps.Caps = 0;
2768 *pCaps->PS20Caps.DynamicFlowControlDepth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
2769 *pCaps->PS20Caps.NumTemps = max(12, GLINFO_LOCATION.ps_arb_max_temps);
2770 *pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
2771 *pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
2773 *pCaps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
2774 *pCaps->MaxPixelShader30InstructionSlots = 0;
2775 } else { /* PS 1.x */
2776 *pCaps->PS20Caps.Caps = 0;
2777 *pCaps->PS20Caps.DynamicFlowControlDepth = 0;
2778 *pCaps->PS20Caps.NumTemps = 0;
2779 *pCaps->PS20Caps.StaticFlowControlDepth = 0;
2780 *pCaps->PS20Caps.NumInstructionSlots = 0;
2782 *pCaps->MaxPShaderInstructionsExecuted = 0;
2783 *pCaps->MaxPixelShader30InstructionSlots = 0;
2787 return WINED3D_OK;
2790 static unsigned int glsl_program_key_hash(void *key) {
2791 glsl_program_key_t *k = (glsl_program_key_t *)key;
2793 unsigned int hash = k->vshader | k->pshader << 16;
2794 hash += ~(hash << 15);
2795 hash ^= (hash >> 10);
2796 hash += (hash << 3);
2797 hash ^= (hash >> 6);
2798 hash += ~(hash << 11);
2799 hash ^= (hash >> 16);
2801 return hash;
2804 static BOOL glsl_program_key_compare(void *keya, void *keyb) {
2805 glsl_program_key_t *ka = (glsl_program_key_t *)keya;
2806 glsl_program_key_t *kb = (glsl_program_key_t *)keyb;
2808 return ka->vshader == kb->vshader && ka->pshader == kb->pshader;
2811 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
2812 and fields being inserted in the middle, a new structure is used in place */
2813 static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, HWND hFocusWindow,
2814 DWORD BehaviourFlags, IWineD3DDevice** ppReturnedDeviceInterface,
2815 IUnknown *parent) {
2817 IWineD3DDeviceImpl *object = NULL;
2818 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2819 WINED3DDISPLAYMODE mode;
2820 int i;
2822 /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
2823 * number and create a device without a 3D adapter for 2D only operation.
2825 if (IWineD3D_GetAdapterCount(iface) && Adapter >= IWineD3D_GetAdapterCount(iface)) {
2826 return WINED3DERR_INVALIDCALL;
2829 /* Create a WineD3DDevice object */
2830 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
2831 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
2832 TRACE("Created WineD3DDevice object @ %p\n", object);
2833 if (NULL == object) {
2834 return WINED3DERR_OUTOFVIDEOMEMORY;
2837 /* Set up initial COM information */
2838 object->lpVtbl = &IWineD3DDevice_Vtbl;
2839 object->ref = 1;
2840 object->wineD3D = iface;
2841 object->adapter = numAdapters ? &Adapters[Adapter] : NULL;
2842 IWineD3D_AddRef(object->wineD3D);
2843 object->parent = parent;
2844 list_init(&object->resources);
2845 list_init(&object->shaders);
2847 if(This->dxVersion == 7) {
2848 object->surface_alignment = 8;
2849 } else {
2850 object->surface_alignment = 4;
2852 object->posFixup[0] = 1.0; /* This is needed to get the x coord unmodified through a MAD */
2854 /* Set the state up as invalid until the device is fully created */
2855 object->state = WINED3DERR_DRIVERINTERNALERROR;
2857 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %x, RetDevInt: %p)\n", This, Adapter, DeviceType,
2858 hFocusWindow, BehaviourFlags, ppReturnedDeviceInterface);
2860 /* Save the creation parameters */
2861 object->createParms.AdapterOrdinal = Adapter;
2862 object->createParms.DeviceType = DeviceType;
2863 object->createParms.hFocusWindow = hFocusWindow;
2864 object->createParms.BehaviorFlags = BehaviourFlags;
2866 /* Initialize other useful values */
2867 object->adapterNo = Adapter;
2868 object->devType = DeviceType;
2870 select_shader_mode(&GLINFO_LOCATION, DeviceType, &object->ps_selected_mode, &object->vs_selected_mode);
2871 if (object->ps_selected_mode == SHADER_GLSL || object->vs_selected_mode == SHADER_GLSL) {
2872 object->shader_backend = &glsl_shader_backend;
2873 object->glsl_program_lookup = hash_table_create(&glsl_program_key_hash, &glsl_program_key_compare);
2874 } else if (object->ps_selected_mode == SHADER_ARB || object->vs_selected_mode == SHADER_ARB) {
2875 object->shader_backend = &arb_program_shader_backend;
2876 } else {
2877 object->shader_backend = &none_shader_backend;
2879 if(FAILED(object->shader_backend->shader_alloc_private((IWineD3DDevice *) object))) {
2880 IWineD3D_Release(object->wineD3D);
2881 HeapFree(GetProcessHeap(), 0, object);
2882 *ppReturnedDeviceInterface = NULL;
2883 return E_OUTOFMEMORY;
2886 /* Prefer the vtable with functions optimized for single dirtifyable objects if the shader
2887 * model can deal with that. It is essentially the same, just with adjusted
2888 * Set*ShaderConstantF implementations
2890 if(object->shader_backend->shader_dirtifyable_constants((IWineD3DDevice *) object)) {
2891 object->lpVtbl = &IWineD3DDevice_DirtyConst_Vtbl;
2894 /* set the state of the device to valid */
2895 object->state = WINED3D_OK;
2897 /* Get the initial screen setup for ddraw */
2898 IWineD3DImpl_GetAdapterDisplayMode(iface, Adapter, &mode);
2900 object->ddraw_width = mode.Width;
2901 object->ddraw_height = mode.Height;
2902 object->ddraw_format = mode.Format;
2904 for(i = 0; i < PATCHMAP_SIZE; i++) {
2905 list_init(&object->patches[i]);
2907 return WINED3D_OK;
2909 #undef GLINFO_LOCATION
2911 static HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
2912 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2913 IUnknown_AddRef(This->parent);
2914 *pParent = This->parent;
2915 return WINED3D_OK;
2918 ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface) {
2919 IUnknown* surfaceParent;
2920 TRACE("(%p) call back\n", pSurface);
2922 /* Now, release the parent, which will take care of cleaning up the surface for us */
2923 IWineD3DSurface_GetParent(pSurface, &surfaceParent);
2924 IUnknown_Release(surfaceParent);
2925 return IUnknown_Release(surfaceParent);
2928 ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pVolume) {
2929 IUnknown* volumeParent;
2930 TRACE("(%p) call back\n", pVolume);
2932 /* Now, release the parent, which will take care of cleaning up the volume for us */
2933 IWineD3DVolume_GetParent(pVolume, &volumeParent);
2934 IUnknown_Release(volumeParent);
2935 return IUnknown_Release(volumeParent);
2938 static BOOL implementation_is_apple(WineD3D_GL_Info *gl_info) {
2939 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
2940 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
2941 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
2943 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
2944 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
2945 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
2946 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
2947 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
2948 * the chance that other implementations support them is rather small since Win32 QuickTime uses
2949 * DirectDraw, not OpenGL.
2951 if(gl_info->supported[APPLE_FENCE] &&
2952 gl_info->supported[APPLE_CLIENT_STORAGE] &&
2953 gl_info->supported[APPLE_FLUSH_RENDER] &&
2954 gl_info->supported[APPLE_YCBCR_422]) {
2955 TRACE_(d3d_caps)("GL_APPLE_fence, GL_APPLE_client_storage, GL_APPLE_flush_render and GL_ycbcr_422 are supported\n");
2956 TRACE_(d3d_caps)("Activating MacOS fixups\n");
2957 return TRUE;
2958 } else {
2959 TRACE_(d3d_caps)("Apple extensions are not supported\n");
2960 TRACE_(d3d_caps)("Not activating MacOS fixups\n");
2961 return FALSE;
2965 #define GLINFO_LOCATION (*gl_info)
2966 static void test_pbo_functionality(WineD3D_GL_Info *gl_info) {
2967 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
2968 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
2969 * all the texture. This function detects this bug by its symptom and disables PBOs
2970 * if the test fails.
2972 * The test uplaods a 4x4 texture via the PBO in the "native" format GL_BGRA,
2973 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
2974 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
2975 * read back is compared to the original. If they are equal PBOs are assumed to work,
2976 * otherwise the PBO extension is disabled.
2978 GLuint texture, pbo;
2979 static const unsigned int pattern[] = {
2980 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
2981 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
2982 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
2983 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
2985 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
2987 if(!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) {
2988 /* No PBO -> No point in testing them */
2989 return;
2992 while(glGetError());
2993 glGenTextures(1, &texture);
2994 glBindTexture(GL_TEXTURE_2D, texture);
2995 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
2996 checkGLcall("Specifying the PBO test texture\n");
2998 GL_EXTCALL(glGenBuffersARB(1, &pbo));
2999 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
3000 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
3001 checkGLcall("Specifying the PBO test pbo\n");
3003 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
3004 checkGLcall("Loading the PBO test texture\n");
3006 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
3007 glFinish(); /* just to be sure */
3009 memset(check, 0, sizeof(check));
3010 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
3011 checkGLcall("Reading back the PBO test texture\n");
3013 glDeleteTextures(1, &texture);
3014 GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
3015 checkGLcall("PBO test cleanup\n");
3017 if(memcmp(check, pattern, sizeof(check)) != 0) {
3018 WARN_(d3d_caps)("PBO test failed, read back data doesn't match original\n");
3019 WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance\n");
3020 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
3021 } else {
3022 TRACE_(d3d_caps)("PBO test successful\n");
3025 #undef GLINFO_LOCATION
3027 /* Certain applications(Steam) complain if we report an outdated driver version. In general,
3028 * reporting a driver version is moot because we are not the Windows driver, and we have different
3029 * bugs, features, etc.
3031 * If a card is not found in this table, the gl driver version is reported
3033 struct driver_version_information {
3034 WORD vendor; /* reported PCI card vendor ID */
3035 WORD card; /* reported PCI card device ID */
3036 WORD hipart_hi, hipart_lo; /* driver hiword to report */
3037 WORD lopart_hi, lopart_lo; /* driver loword to report */
3040 static const struct driver_version_information driver_version_table[] = {
3041 /* Nvidia drivers. Geforce FX and newer cards are supported by the current driver */
3042 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, 7, 15, 10, 16921 },
3043 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, 7, 15, 10, 16921 },
3044 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, 7, 15, 10, 16921 },
3045 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, 7, 15, 10, 16921 },
3046 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, 7, 15, 10, 16921 },
3047 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, 7, 15, 10, 16921 },
3048 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, 7, 15, 10, 16921 },
3049 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, 7, 15, 10, 16921 },
3050 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, 7, 15, 10, 16921 },
3051 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, 7, 15, 10, 16921 },
3052 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, 7, 15, 10, 16921 },
3053 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, 7, 15, 10, 16921 },
3054 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, 7, 15, 10, 16921 },
3055 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, 7, 15, 10, 16921 },
3057 /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode */
3058 {VENDOR_ATI, CARD_ATI_RADEON_9500, 6, 14, 10, 6764 },
3059 {VENDOR_ATI, CARD_ATI_RADEON_X700, 6, 14, 10, 6764 },
3060 {VENDOR_ATI, CARD_ATI_RADEON_X1600, 6, 14, 10, 6764 },
3061 {VENDOR_ATI, CARD_ATI_RADEON_HD2300, 6, 14, 10, 6764 },
3062 {VENDOR_ATI, CARD_ATI_RADEON_HD2600, 6, 14, 10, 6764 },
3063 {VENDOR_ATI, CARD_ATI_RADEON_HD2900, 6, 14, 10, 6764 },
3065 /* TODO: Add information about legacy nvidia and ATI hardware, Intel and other cards */
3068 static void fixup_extensions(WineD3D_GL_Info *gl_info) {
3069 unsigned int i;
3070 BOOL apple = implementation_is_apple(gl_info);
3072 if(apple) {
3073 /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
3074 * used it falls back to software. While the compiler can detect if the shader uses all declared
3075 * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
3076 * using relative addressing falls back to software.
3078 * ARB vp gives the correct amount of uniforms, so use it instead of GLSL
3080 if(gl_info->vs_glsl_constantsF <= gl_info->vs_arb_constantsF) {
3081 FIXME("GLSL doesn't advertise more vertex shader uniforms than ARB. Driver fixup outdated?\n");
3082 } else {
3083 TRACE("Driver claims %u GLSL vs uniforms, replacing with %u ARB vp uniforms\n",
3084 gl_info->vs_glsl_constantsF, gl_info->vs_arb_constantsF);
3085 gl_info->vs_glsl_constantsF = gl_info->vs_arb_constantsF;
3088 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
3089 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
3090 * If real NP2 textures are used, the driver falls back to software. So remove the supported
3091 * flag for this extension
3093 if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] && gl_info->gl_vendor == VENDOR_ATI) {
3094 if(gl_info->gl_card == CARD_ATI_RADEON_X700 || gl_info->gl_card == CARD_ATI_RADEON_X1600 ||
3095 gl_info->gl_card == CARD_ATI_RADEON_9500 || gl_info->gl_card == CARD_ATI_RADEON_8500 ||
3096 gl_info->gl_card == CARD_ATI_RADEON_7200 || gl_info->gl_card == CARD_ATI_RAGE_128PRO) {
3097 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing\n");
3098 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
3099 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
3103 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
3104 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
3105 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
3106 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
3107 * according to the spec.
3109 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
3110 * makes the shader slower and eats instruction slots which should be available to the d3d app.
3112 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
3113 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
3114 * this workaround is activated on cards that do not need it, it won't break things, just affect
3115 * performance negatively.
3117 if(gl_info->gl_vendor == VENDOR_INTEL ||
3118 (gl_info->gl_vendor == VENDOR_ATI && gl_info->gl_card != CARD_ATI_RADEON_X1600)) {
3119 TRACE("Enabling vertex texture coord fixes in vertex shaders\n");
3120 gl_info->set_texcoord_w = TRUE;
3124 /* Find out if PBOs work as they are supposed to */
3125 test_pbo_functionality(gl_info);
3127 /* Fixup the driver version */
3128 for(i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++) {
3129 if(gl_info->gl_vendor == driver_version_table[i].vendor &&
3130 gl_info->gl_card == driver_version_table[i].card) {
3131 TRACE_(d3d_caps)("Found card 0x%04x, 0x%04x in driver version DB\n", gl_info->gl_vendor, gl_info->gl_card);
3133 gl_info->driver_version = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
3134 driver_version_table[i].lopart_lo);
3135 gl_info->driver_version_hipart = MAKEDWORD_VERSION(driver_version_table[i].hipart_hi,
3136 driver_version_table[i].hipart_lo);
3137 break;
3142 void invalid_func(void *data) {
3143 ERR("Invalid vertex attribute function called\n");
3144 DebugBreak();
3147 #define GLINFO_LOCATION (Adapters[0].gl_info)
3149 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
3150 * the extension detection and are used in drawStridedSlow
3152 static void position_d3dcolor(void *data) {
3153 DWORD pos = *((DWORD *) data);
3155 FIXME("Add a test for fixed function position from d3dcolor type\n");
3156 glVertex4s(D3DCOLOR_B_R(pos),
3157 D3DCOLOR_B_G(pos),
3158 D3DCOLOR_B_B(pos),
3159 D3DCOLOR_B_A(pos));
3161 static void position_float4(void *data) {
3162 GLfloat *pos = (float *) data;
3164 if (pos[3] < eps && pos[3] > -eps)
3165 glVertex3fv(pos);
3166 else {
3167 float w = 1.0 / pos[3];
3169 glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
3173 static void diffuse_d3dcolor(void *data) {
3174 DWORD diffuseColor = *((DWORD *) data);
3176 glColor4ub(D3DCOLOR_B_R(diffuseColor),
3177 D3DCOLOR_B_G(diffuseColor),
3178 D3DCOLOR_B_B(diffuseColor),
3179 D3DCOLOR_B_A(diffuseColor));
3182 static void specular_d3dcolor(void *data) {
3183 DWORD specularColor = *((DWORD *) data);
3185 GL_EXTCALL(glSecondaryColor3ubEXT)(D3DCOLOR_B_R(specularColor),
3186 D3DCOLOR_B_G(specularColor),
3187 D3DCOLOR_B_B(specularColor));
3189 static void warn_no_specular_func(void *data) {
3190 WARN("GL_EXT_secondary_color not supported\n");
3193 void fillGLAttribFuncs(WineD3D_GL_Info *gl_info) {
3194 position_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3195 position_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3196 position_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glVertex3fv;
3197 position_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) position_float4;
3198 position_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) position_d3dcolor;
3199 position_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3200 position_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3201 position_funcs[WINED3DDECLTYPE_SHORT4] = (void *) glVertex2sv;
3202 position_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3203 position_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3204 position_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3205 position_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3206 position_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3207 position_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3208 position_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3209 position_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3210 position_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3212 diffuse_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3213 diffuse_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3214 diffuse_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glColor3fv;
3215 diffuse_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) glColor4fv;
3216 diffuse_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) diffuse_d3dcolor;
3217 diffuse_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3218 diffuse_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3219 diffuse_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3220 diffuse_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) glColor4ubv;
3221 diffuse_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3222 diffuse_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) glColor4sv;
3223 diffuse_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3224 diffuse_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) glColor4usv;
3225 diffuse_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3226 diffuse_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3227 diffuse_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3228 diffuse_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3230 /* No 4 component entry points here */
3231 specular_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3232 specular_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3233 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
3234 specular_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) GL_EXTCALL(glSecondaryColor3fvEXT);
3235 } else {
3236 specular_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) warn_no_specular_func;
3238 specular_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) invalid_func;
3239 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
3240 specular_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) specular_d3dcolor;
3241 } else {
3242 specular_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) warn_no_specular_func;
3244 specular_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3245 specular_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3246 specular_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3247 specular_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3248 specular_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3249 specular_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3250 specular_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3251 specular_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3252 specular_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3253 specular_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3254 specular_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3255 specular_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3257 /* Only 3 component entry points here. Test how others behave. Float4 normals are used
3258 * by one of our tests, trying to pass it to the pixel shader, which fails on Windows.
3260 normal_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3261 normal_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3262 normal_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glNormal3fv;
3263 normal_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) glNormal3fv; /* Just ignore the 4th value */
3264 normal_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) invalid_func;
3265 normal_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3266 normal_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3267 normal_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3268 normal_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3269 normal_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3270 normal_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3271 normal_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3272 normal_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3273 normal_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3274 normal_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3275 normal_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3276 normal_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3279 #define PUSH1(att) attribs[nAttribs++] = (att);
3280 BOOL InitAdapters(void) {
3281 static HMODULE mod_gl;
3282 BOOL ret;
3283 int ps_selected_mode, vs_selected_mode;
3285 /* No need to hold any lock. The calling library makes sure only one thread calls
3286 * wined3d simultaneously
3288 if(numAdapters > 0) return TRUE;
3290 TRACE("Initializing adapters\n");
3292 if(!mod_gl) {
3293 #ifdef USE_WIN32_OPENGL
3294 #define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
3295 mod_gl = LoadLibraryA("opengl32.dll");
3296 if(!mod_gl) {
3297 ERR("Can't load opengl32.dll!\n");
3298 return FALSE;
3300 #else
3301 #define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
3302 /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
3303 mod_gl = GetModuleHandleA("gdi32.dll");
3304 #endif
3307 /* Load WGL core functions from opengl32.dll */
3308 #define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn);
3309 WGL_FUNCS_GEN;
3310 #undef USE_WGL_FUNC
3312 if(!pwglGetProcAddress) {
3313 ERR("Unable to load wglGetProcAddress!\n");
3314 return FALSE;
3317 /* Dynamically load all GL core functions */
3318 GL_FUNCS_GEN;
3319 #undef USE_GL_FUNC
3321 /* For now only one default adapter */
3323 int iPixelFormat;
3324 int attribs[8];
3325 int values[8];
3326 int nAttribs = 0;
3327 int res;
3328 WineD3D_PixelFormat *cfgs;
3329 int attribute;
3330 DISPLAY_DEVICEW DisplayDevice;
3331 HDC hdc;
3333 TRACE("Initializing default adapter\n");
3334 Adapters[0].num = 0;
3335 Adapters[0].monitorPoint.x = -1;
3336 Adapters[0].monitorPoint.y = -1;
3338 if (!WineD3D_CreateFakeGLContext()) {
3339 ERR("Failed to get a gl context for default adapter\n");
3340 HeapFree(GetProcessHeap(), 0, Adapters);
3341 WineD3D_ReleaseFakeGLContext();
3342 return FALSE;
3345 ret = IWineD3DImpl_FillGLCaps(&Adapters[0].gl_info);
3346 if(!ret) {
3347 ERR("Failed to initialize gl caps for default adapter\n");
3348 HeapFree(GetProcessHeap(), 0, Adapters);
3349 WineD3D_ReleaseFakeGLContext();
3350 return FALSE;
3352 ret = initPixelFormats(&Adapters[0].gl_info);
3353 if(!ret) {
3354 ERR("Failed to init gl formats\n");
3355 HeapFree(GetProcessHeap(), 0, Adapters);
3356 WineD3D_ReleaseFakeGLContext();
3357 return FALSE;
3360 hdc = pwglGetCurrentDC();
3361 if(!hdc) {
3362 ERR("Failed to get gl HDC\n");
3363 HeapFree(GetProcessHeap(), 0, Adapters);
3364 WineD3D_ReleaseFakeGLContext();
3365 return FALSE;
3368 Adapters[0].driver = "Display";
3369 Adapters[0].description = "Direct3D HAL";
3371 /* Use the VideoRamSize registry setting when set */
3372 if(wined3d_settings.emulated_textureram)
3373 Adapters[0].TextureRam = wined3d_settings.emulated_textureram;
3374 else
3375 Adapters[0].TextureRam = Adapters[0].gl_info.vidmem;
3376 Adapters[0].UsedTextureRam = 0;
3377 TRACE("Emulating %dMB of texture ram\n", Adapters[0].TextureRam/(1024*1024));
3379 /* Initialize the Adapter's DeviceName which is required for ChangeDisplaySettings and friends */
3380 DisplayDevice.cb = sizeof(DisplayDevice);
3381 EnumDisplayDevicesW(NULL, 0 /* Adapter 0 = iDevNum 0 */, &DisplayDevice, 0);
3382 TRACE("DeviceName: %s\n", debugstr_w(DisplayDevice.DeviceName));
3383 strcpyW(Adapters[0].DeviceName, DisplayDevice.DeviceName);
3385 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
3386 GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, &attribute, &Adapters[0].nCfgs));
3388 Adapters[0].cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Adapters[0].nCfgs *sizeof(WineD3D_PixelFormat));
3389 cfgs = Adapters[0].cfgs;
3390 PUSH1(WGL_RED_BITS_ARB)
3391 PUSH1(WGL_GREEN_BITS_ARB)
3392 PUSH1(WGL_BLUE_BITS_ARB)
3393 PUSH1(WGL_ALPHA_BITS_ARB)
3394 PUSH1(WGL_DEPTH_BITS_ARB)
3395 PUSH1(WGL_STENCIL_BITS_ARB)
3397 for(iPixelFormat=1; iPixelFormat<=Adapters[0].nCfgs; iPixelFormat++) {
3398 res = GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, nAttribs, attribs, values));
3400 if(!res)
3401 continue;
3403 /* Cache the pixel format */
3404 cfgs->iPixelFormat = iPixelFormat;
3405 cfgs->redSize = values[0];
3406 cfgs->greenSize = values[1];
3407 cfgs->blueSize = values[2];
3408 cfgs->alphaSize = values[3];
3409 cfgs->depthSize = values[4];
3410 cfgs->stencilSize = values[5];
3412 TRACE("iPixelFormat=%d, RGBA=%d/%d/%d/%d, depth=%d, stencil=%d\n", cfgs->iPixelFormat, cfgs->redSize, cfgs->greenSize, cfgs->blueSize, cfgs->alphaSize, cfgs->depthSize, cfgs->stencilSize);
3413 cfgs++;
3416 fixup_extensions(&Adapters[0].gl_info);
3418 WineD3D_ReleaseFakeGLContext();
3420 select_shader_mode(&Adapters[0].gl_info, WINED3DDEVTYPE_HAL, &ps_selected_mode, &vs_selected_mode);
3421 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &Adapters[0].gl_info);
3422 fillGLAttribFuncs(&Adapters[0].gl_info);
3423 init_type_lookup(&Adapters[0].gl_info);
3425 numAdapters = 1;
3426 TRACE("%d adapters successfully initialized\n", numAdapters);
3428 return TRUE;
3430 #undef PUSH1
3431 #undef GLINFO_LOCATION
3433 /**********************************************************
3434 * IWineD3D VTbl follows
3435 **********************************************************/
3437 const IWineD3DVtbl IWineD3D_Vtbl =
3439 /* IUnknown */
3440 IWineD3DImpl_QueryInterface,
3441 IWineD3DImpl_AddRef,
3442 IWineD3DImpl_Release,
3443 /* IWineD3D */
3444 IWineD3DImpl_GetParent,
3445 IWineD3DImpl_GetAdapterCount,
3446 IWineD3DImpl_RegisterSoftwareDevice,
3447 IWineD3DImpl_GetAdapterMonitor,
3448 IWineD3DImpl_GetAdapterModeCount,
3449 IWineD3DImpl_EnumAdapterModes,
3450 IWineD3DImpl_GetAdapterDisplayMode,
3451 IWineD3DImpl_GetAdapterIdentifier,
3452 IWineD3DImpl_CheckDeviceMultiSampleType,
3453 IWineD3DImpl_CheckDepthStencilMatch,
3454 IWineD3DImpl_CheckDeviceType,
3455 IWineD3DImpl_CheckDeviceFormat,
3456 IWineD3DImpl_CheckDeviceFormatConversion,
3457 IWineD3DImpl_GetDeviceCaps,
3458 IWineD3DImpl_CreateDevice