wined3d: Add ENTER_GL/LEAVE_GL in surface_bind_and_dirtify.
[wine.git] / dlls / wined3d / directx.c
blob8e14309aa55802ef2ed4629d72364428a7b2af6f
1 /*
2 * IWineD3D implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 /* Compile time diagnostics: */
27 #ifndef DEBUG_SINGLE_MODE
28 /* Set to 1 to force only a single display mode to be exposed: */
29 #define DEBUG_SINGLE_MODE 0
30 #endif
33 #include "config.h"
34 #include <assert.h>
35 #include "wined3d_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
38 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
40 /* The d3d device ID */
41 static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
43 /* Extension detection */
44 static const struct {
45 const char *extension_string;
46 GL_SupportedExt extension;
47 DWORD version;
48 } EXTENSION_MAP[] = {
49 /* APPLE */
50 {"GL_APPLE_client_storage", APPLE_CLIENT_STORAGE, 0 },
51 {"GL_APPLE_fence", APPLE_FENCE, 0 },
52 {"GL_APPLE_flush_render", APPLE_FLUSH_RENDER, 0 },
53 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422, 0 },
54 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS, 0 },
56 /* ATI */
57 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL, 0 },
58 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3, 0 },
59 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE, 0 },
60 {"GL_ATI_envmap_bumpmap", ATI_ENVMAP_BUMPMAP, 0 },
61 {"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER, 0 },
63 /* ARB */
64 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS, 0 },
65 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM, 0 },
66 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER, 0 },
67 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL, 0 },
68 {"GL_ARB_imaging", ARB_IMAGING, 0 },
69 {"GL_ARB_multisample", ARB_MULTISAMPLE, 0 }, /* needs GLX_ARB_MULTISAMPLE as well */
70 {"GL_ARB_multitexture", ARB_MULTITEXTURE, 0 },
71 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY, 0 },
72 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT, 0 },
73 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS, 0 },
74 {"GL_ARB_point_sprite", ARB_POINT_SPRITE, 0 },
75 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP, 0 },
76 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION, 0 },
77 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP, 0 },
78 {"GL_ARB_texture_env_add", ARB_TEXTURE_ENV_ADD, 0 },
79 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE, 0 },
80 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3, 0 },
81 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT, 0 },
82 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT, 0 },
83 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO, 0 },
84 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE, 0 },
85 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND, 0 },
86 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT, 0 },
87 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM, 0 },
88 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER, 0 },
89 {"GL_ARB_shader_objects", ARB_SHADER_OBJECTS, 0 },
91 /* EXT */
92 {"GL_EXT_blend_color", EXT_BLEND_COLOR, 0 },
93 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX, 0 },
94 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE, 0 },
95 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE, 0 },
96 {"GL_EXT_fog_coord", EXT_FOG_COORD, 0 },
97 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT, 0 },
98 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT, 0 },
99 {"GL_EXT_paletted_texture", EXT_PALETTED_TEXTURE, 0 },
100 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS, 0 },
101 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR, 0 },
102 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE, 0 },
103 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP, 0 },
104 {"GL_EXT_texture3D", EXT_TEXTURE3D, MAKEDWORD_VERSION(1, 2) },
105 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC, 0 },
106 {"GL_EXT_texture_env_add", EXT_TEXTURE_ENV_ADD, 0 },
107 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE, 0 },
108 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3, 0 },
109 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB, 0 },
110 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC, 0 },
111 {"GL_EXT_texture_lod", EXT_TEXTURE_LOD, 0 },
112 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS, 0 },
113 {"GL_EXT_vertex_shader", EXT_VERTEX_SHADER, 0 },
114 {"GL_EXT_vertex_weighting", EXT_VERTEX_WEIGHTING, 0 },
115 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS, 0 },
117 /* NV */
118 {"GL_NV_half_float", NV_HALF_FLOAT, 0 },
119 {"GL_NV_fence", NV_FENCE, 0 },
120 {"GL_NV_fog_distance", NV_FOG_DISTANCE, 0 },
121 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM, 0 },
122 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2, 0 },
123 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS, 0 },
124 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2, 0 },
125 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION, 0 },
126 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4, 0 },
127 {"GL_NV_texture_shader", NV_TEXTURE_SHADER, 0 },
128 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2, 0 },
129 {"GL_NV_texture_shader3", NV_TEXTURE_SHADER3, 0 },
130 {"GL_NV_occlusion_query", NV_OCCLUSION_QUERY, 0 },
131 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM, 0 },
132 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1, 0 },
133 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2, 0 },
134 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3, 0 },
135 {"GL_NV_depth_clamp", NV_DEPTH_CLAMP, 0 },
136 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT, 0 },
138 /* SGI */
139 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP, 0 },
142 /**********************************************************
143 * Utility functions follow
144 **********************************************************/
146 /* Adapters */
147 static int numAdapters = 0;
148 static struct WineD3DAdapter Adapters[1];
150 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat);
152 /* lookup tables */
153 int minLookup[MAX_LOOKUPS];
154 int maxLookup[MAX_LOOKUPS];
155 DWORD *stateLookup[MAX_LOOKUPS];
157 DWORD minMipLookup[WINED3DTEXF_ANISOTROPIC + 1][WINED3DTEXF_LINEAR + 1];
159 /* drawStridedSlow attributes */
160 glAttribFunc position_funcs[WINED3DDECLTYPE_UNUSED];
161 glAttribFunc diffuse_funcs[WINED3DDECLTYPE_UNUSED];
162 glAttribFunc specular_funcs[WINED3DDECLTYPE_UNUSED];
163 glAttribFunc normal_funcs[WINED3DDECLTYPE_UNUSED];
164 glTexAttribFunc texcoord_funcs[WINED3DDECLTYPE_UNUSED];
167 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created
168 * ie there is no GL Context - Get a default rendering context to enable the
169 * function query some info from GL
172 static int wined3d_fake_gl_context_ref = 0;
173 static BOOL wined3d_fake_gl_context_foreign;
174 static BOOL wined3d_fake_gl_context_available = FALSE;
175 static HDC wined3d_fake_gl_context_hdc = NULL;
176 static HWND wined3d_fake_gl_context_hwnd = NULL;
178 static CRITICAL_SECTION wined3d_fake_gl_context_cs;
179 static CRITICAL_SECTION_DEBUG wined3d_fake_gl_context_cs_debug =
181 0, 0, &wined3d_fake_gl_context_cs,
182 { &wined3d_fake_gl_context_cs_debug.ProcessLocksList,
183 &wined3d_fake_gl_context_cs_debug.ProcessLocksList },
184 0, 0, { (DWORD_PTR)(__FILE__ ": wined3d_fake_gl_context_cs") }
186 static CRITICAL_SECTION wined3d_fake_gl_context_cs = { &wined3d_fake_gl_context_cs_debug, -1, 0, 0, 0, 0 };
188 static void WineD3D_ReleaseFakeGLContext(void) {
189 HGLRC glCtx;
191 EnterCriticalSection(&wined3d_fake_gl_context_cs);
193 if(!wined3d_fake_gl_context_available) {
194 TRACE_(d3d_caps)("context not available\n");
195 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
196 return;
199 glCtx = pwglGetCurrentContext();
201 TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref);
202 if (0 == (--wined3d_fake_gl_context_ref) ) {
203 if(!wined3d_fake_gl_context_foreign && glCtx) {
204 TRACE_(d3d_caps)("destroying fake GL context\n");
205 pwglMakeCurrent(NULL, NULL);
206 pwglDeleteContext(glCtx);
208 if(wined3d_fake_gl_context_hdc)
209 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
210 wined3d_fake_gl_context_hdc = NULL; /* Make sure we don't think that it is still around */
211 if(wined3d_fake_gl_context_hwnd)
212 DestroyWindow(wined3d_fake_gl_context_hwnd);
213 wined3d_fake_gl_context_hwnd = NULL;
214 wined3d_fake_gl_context_available = FALSE;
216 assert(wined3d_fake_gl_context_ref >= 0);
218 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
221 static BOOL WineD3D_CreateFakeGLContext(void) {
222 HGLRC glCtx = NULL;
224 EnterCriticalSection(&wined3d_fake_gl_context_cs);
226 TRACE("getting context...\n");
227 if(wined3d_fake_gl_context_ref > 0) goto ret;
228 assert(0 == wined3d_fake_gl_context_ref);
230 wined3d_fake_gl_context_foreign = TRUE;
232 glCtx = pwglGetCurrentContext();
233 if (!glCtx) {
234 PIXELFORMATDESCRIPTOR pfd;
235 int iPixelFormat;
237 wined3d_fake_gl_context_foreign = FALSE;
239 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes */
240 wined3d_fake_gl_context_hwnd = CreateWindowA("WineD3D_OpenGL", "WineD3D fake window", WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
241 if(!wined3d_fake_gl_context_hwnd) {
242 ERR("HWND creation failed!\n");
243 goto fail;
245 wined3d_fake_gl_context_hdc = GetDC(wined3d_fake_gl_context_hwnd);
246 if(!wined3d_fake_gl_context_hdc) {
247 ERR("GetDC failed!\n");
248 goto fail;
251 /* PixelFormat selection */
252 ZeroMemory(&pfd, sizeof(pfd));
253 pfd.nSize = sizeof(pfd);
254 pfd.nVersion = 1;
255 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;/*PFD_GENERIC_ACCELERATED*/
256 pfd.iPixelType = PFD_TYPE_RGBA;
257 pfd.cColorBits = 32;
258 pfd.iLayerType = PFD_MAIN_PLANE;
260 iPixelFormat = ChoosePixelFormat(wined3d_fake_gl_context_hdc, &pfd);
261 if(!iPixelFormat) {
262 /* If this happens something is very wrong as ChoosePixelFormat barely fails */
263 ERR("Can't find a suitable iPixelFormat\n");
264 goto fail;
266 DescribePixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, sizeof(pfd), &pfd);
267 SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd);
269 /* Create a GL context */
270 glCtx = pwglCreateContext(wined3d_fake_gl_context_hdc);
271 if (!glCtx) {
272 WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
273 goto fail;
276 /* Make it the current GL context */
277 if (!pwglMakeCurrent(wined3d_fake_gl_context_hdc, glCtx)) {
278 WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
279 goto fail;
283 ret:
284 TRACE("incrementing ref from %i\n", wined3d_fake_gl_context_ref);
285 wined3d_fake_gl_context_ref++;
286 wined3d_fake_gl_context_available = TRUE;
287 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
288 return TRUE;
289 fail:
290 if(wined3d_fake_gl_context_hdc)
291 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
292 wined3d_fake_gl_context_hdc = NULL;
293 if(wined3d_fake_gl_context_hwnd)
294 DestroyWindow(wined3d_fake_gl_context_hwnd);
295 wined3d_fake_gl_context_hwnd = NULL;
296 if(glCtx) pwglDeleteContext(glCtx);
297 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
298 return FALSE;
301 /* Adjust the amount of used texture memory */
302 long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram){
303 UINT Adapter = D3DDevice->adapterNo;
305 Adapters[Adapter].UsedTextureRam += glram;
306 TRACE("Adjusted gl ram by %ld to %d\n", glram, Adapters[Adapter].UsedTextureRam);
307 return Adapters[Adapter].UsedTextureRam;
310 /**********************************************************
311 * IUnknown parts follows
312 **********************************************************/
314 static HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
316 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
318 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
319 if (IsEqualGUID(riid, &IID_IUnknown)
320 || IsEqualGUID(riid, &IID_IWineD3DBase)
321 || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
322 IUnknown_AddRef(iface);
323 *ppobj = This;
324 return S_OK;
326 *ppobj = NULL;
327 return E_NOINTERFACE;
330 static ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
331 IWineD3DImpl *This = (IWineD3DImpl *)iface;
332 ULONG refCount = InterlockedIncrement(&This->ref);
334 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
335 return refCount;
338 static ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
339 IWineD3DImpl *This = (IWineD3DImpl *)iface;
340 ULONG ref;
341 TRACE("(%p) : Releasing from %d\n", This, This->ref);
342 ref = InterlockedDecrement(&This->ref);
343 if (ref == 0) {
344 HeapFree(GetProcessHeap(), 0, This);
347 return ref;
350 /* Set the shader type for this device, depending on the given capabilities,
351 * the device type, and the user preferences in wined3d_settings */
353 void select_shader_mode(
354 WineD3D_GL_Info *gl_info,
355 WINED3DDEVTYPE DeviceType,
356 int* ps_selected,
357 int* vs_selected) {
359 if (wined3d_settings.vs_mode == VS_NONE) {
360 *vs_selected = SHADER_NONE;
361 } else if (gl_info->supported[ARB_VERTEX_SHADER] && wined3d_settings.glslRequested) {
362 /* Geforce4 cards support GLSL but for vertex shaders only. Further its reported GLSL caps are
363 * wrong. This combined with the fact that glsl won't offer more features or performance, use ARB
364 * shaders only on this card. */
365 if(gl_info->vs_nv_version && gl_info->vs_nv_version < VS_VERSION_20)
366 *vs_selected = SHADER_ARB;
367 else
368 *vs_selected = SHADER_GLSL;
369 } else if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
370 *vs_selected = SHADER_ARB;
371 } else {
372 *vs_selected = SHADER_NONE;
375 if (wined3d_settings.ps_mode == PS_NONE) {
376 *ps_selected = SHADER_NONE;
377 } else if (gl_info->supported[ARB_FRAGMENT_SHADER] && wined3d_settings.glslRequested) {
378 *ps_selected = SHADER_GLSL;
379 } else if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
380 *ps_selected = SHADER_ARB;
381 } else if (gl_info->supported[ATI_FRAGMENT_SHADER]) {
382 *ps_selected = SHADER_ATI;
383 } else {
384 *ps_selected = SHADER_NONE;
388 /** Select the number of report maximum shader constants based on the selected shader modes */
389 static void select_shader_max_constants(
390 int ps_selected_mode,
391 int vs_selected_mode,
392 WineD3D_GL_Info *gl_info) {
394 switch (vs_selected_mode) {
395 case SHADER_GLSL:
396 /* Subtract the other potential uniforms from the max available (bools, ints, and 1 row of projection matrix) */
397 gl_info->max_vshader_constantsF = gl_info->vs_glsl_constantsF - (MAX_CONST_B / 4) - MAX_CONST_I - 1;
398 break;
399 case SHADER_ARB:
400 /* We have to subtract any other PARAMs that we might use in our shader programs.
401 * ATI seems to count 2 implicit PARAMs when we use fog and NVIDIA counts 1,
402 * and we reference one row of the PROJECTION matrix which counts as 1 PARAM. */
403 gl_info->max_vshader_constantsF = gl_info->vs_arb_constantsF - 3;
404 break;
405 default:
406 gl_info->max_vshader_constantsF = 0;
407 break;
410 switch (ps_selected_mode) {
411 case SHADER_GLSL:
412 /* Subtract the other potential uniforms from the max available (bools & ints), and 2 states for fog.
413 * In theory the texbem instruction may need one more shader constant too. But lets assume
414 * that a sm <= 1.3 shader does not need all the uniforms provided by a glsl-capable card,
415 * and lets not take away a uniform needlessly from all other shaders.
417 gl_info->max_pshader_constantsF = gl_info->ps_glsl_constantsF - (MAX_CONST_B / 4) - MAX_CONST_I - 2;
418 break;
419 case SHADER_ARB:
420 /* The arb shader only loads the bump mapping environment matrix into the shader if it finds
421 * a free constant to do that, so only reduce the number of available constants by 2 for the fog states.
423 gl_info->max_pshader_constantsF = gl_info->ps_arb_constantsF - 2;
424 break;
425 default:
426 gl_info->max_pshader_constantsF = 0;
427 break;
431 /**********************************************************
432 * IWineD3D parts follows
433 **********************************************************/
435 #define GLINFO_LOCATION (*gl_info)
436 static inline BOOL test_arb_vs_offset_limit(WineD3D_GL_Info *gl_info) {
437 GLuint prog;
438 BOOL ret = FALSE;
439 const char *testcode =
440 "!!ARBvp1.0\n"
441 "PARAM C[66] = { program.env[0..65] };\n"
442 "ADDRESS A0;"
443 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
444 "ARL A0.x, zero.x;\n"
445 "MOV result.position, C[A0.x + 65];\n"
446 "END\n";
448 while(glGetError());
449 GL_EXTCALL(glGenProgramsARB(1, &prog));
450 if(!prog) {
451 ERR("Failed to create an ARB offset limit test program\n");
453 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
454 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
455 strlen(testcode), testcode));
456 if(glGetError() != 0) {
457 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
458 TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
459 ret = TRUE;
460 } else TRACE("OpenGL implementation allows offsets > 63\n");
462 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
463 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
464 checkGLcall("ARB vp offset limit test cleanup\n");
466 return ret;
469 static DWORD ver_for_ext(GL_SupportedExt ext)
471 unsigned int i;
472 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
473 if(EXTENSION_MAP[i].extension == ext) {
474 return EXTENSION_MAP[i].version;
477 return 0;
480 BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
481 const char *GL_Extensions = NULL;
482 const char *WGL_Extensions = NULL;
483 const char *gl_string = NULL;
484 const char *gl_string_cursor = NULL;
485 GLint gl_max;
486 GLfloat gl_floatv[2];
487 int major = 1, minor = 0;
488 BOOL return_value = TRUE;
489 unsigned i;
490 HDC hdc;
491 unsigned int vidmem=0;
493 TRACE_(d3d_caps)("(%p)\n", gl_info);
495 ENTER_GL();
497 gl_string = (const char *) glGetString(GL_RENDERER);
498 if (NULL == gl_string)
499 gl_string = "None";
500 strcpy(gl_info->gl_renderer, gl_string);
502 gl_string = (const char *) glGetString(GL_VENDOR);
503 TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
504 if (gl_string != NULL) {
505 /* Fill in the GL vendor */
506 if (strstr(gl_string, "NVIDIA")) {
507 gl_info->gl_vendor = VENDOR_NVIDIA;
508 } else if (strstr(gl_string, "ATI")) {
509 gl_info->gl_vendor = VENDOR_ATI;
510 } else if (strstr(gl_string, "Intel(R)") ||
511 strstr(gl_info->gl_renderer, "Intel(R)") ||
512 strstr(gl_string, "Intel Inc.")) {
513 gl_info->gl_vendor = VENDOR_INTEL;
514 } else if (strstr(gl_string, "Mesa")) {
515 gl_info->gl_vendor = VENDOR_MESA;
516 } else {
517 gl_info->gl_vendor = VENDOR_WINE;
519 } else {
520 gl_info->gl_vendor = VENDOR_WINE;
524 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
526 /* Parse the GL_VERSION field into major and minor information */
527 gl_string = (const char *) glGetString(GL_VERSION);
528 if (gl_string != NULL) {
530 /* First, parse the generic opengl version. This is supposed not to be convoluted with
531 * driver specific information
533 gl_string_cursor = gl_string;
534 major = atoi(gl_string_cursor);
535 if(major <= 0) {
536 ERR("Invalid opengl major version: %d\n", major);
538 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
539 ++gl_string_cursor;
541 if (*gl_string_cursor++ != '.') {
542 ERR_(d3d_caps)("Invalid opengl version string: %s\n", debugstr_a(gl_string));
544 minor = atoi(gl_string_cursor);
545 TRACE_(d3d_caps)("Found OpenGL version: %d.%d\n", major, minor);
546 gl_info->gl_version = MAKEDWORD_VERSION(major, minor);
548 /* Now parse the driver specific string which we'll report to the app */
549 switch (gl_info->gl_vendor) {
550 case VENDOR_NVIDIA:
551 gl_string_cursor = strstr(gl_string, "NVIDIA");
552 if (!gl_string_cursor) {
553 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
554 break;
557 gl_string_cursor = strstr(gl_string_cursor, " ");
558 if (!gl_string_cursor) {
559 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
560 break;
563 while (*gl_string_cursor == ' ') {
564 ++gl_string_cursor;
567 if (!*gl_string_cursor) {
568 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
569 break;
572 major = atoi(gl_string_cursor);
573 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
574 ++gl_string_cursor;
577 if (*gl_string_cursor++ != '.') {
578 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
579 break;
582 minor = atoi(gl_string_cursor);
583 minor = major*100+minor;
584 major = 10;
586 break;
588 case VENDOR_ATI:
589 major = minor = 0;
590 gl_string_cursor = strchr(gl_string, '-');
591 if (gl_string_cursor) {
592 int error = 0;
593 gl_string_cursor++;
595 /* Check if version number is of the form x.y.z */
596 if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
597 error = 1;
598 if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
599 error = 1;
600 if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
601 error = 1;
602 if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
603 error = 1;
605 /* Mark version number as malformed */
606 if (error)
607 gl_string_cursor = 0;
610 if (!gl_string_cursor)
611 WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
612 else {
613 major = *gl_string_cursor - '0';
614 minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
616 break;
618 case VENDOR_INTEL:
619 /* Apple and Mesa version strings look differently, but both provide intel drivers */
620 if(strstr(gl_string, "APPLE")) {
621 /* [0-9]+.[0-9]+ APPLE-[0-9]+.[0.9]+.[0.9]+
622 * We only need the first part, and use the APPLE as identification
623 * "1.2 APPLE-1.4.56"
625 gl_string_cursor = gl_string;
626 major = atoi(gl_string_cursor);
627 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
628 ++gl_string_cursor;
631 if (*gl_string_cursor++ != '.') {
632 ERR_(d3d_caps)("Invalid MacOS-Intel version string: %s\n", debugstr_a(gl_string));
633 break;
636 minor = atoi(gl_string_cursor);
637 break;
640 case VENDOR_MESA:
641 gl_string_cursor = strstr(gl_string, "Mesa");
642 gl_string_cursor = strstr(gl_string_cursor, " ");
643 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
644 if (*gl_string_cursor) {
645 char tmp[16];
646 int cursor = 0;
648 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
649 tmp[cursor++] = *gl_string_cursor;
650 ++gl_string_cursor;
652 tmp[cursor] = 0;
653 major = atoi(tmp);
655 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
656 ++gl_string_cursor;
658 cursor = 0;
659 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
660 tmp[cursor++] = *gl_string_cursor;
661 ++gl_string_cursor;
663 tmp[cursor] = 0;
664 minor = atoi(tmp);
666 break;
668 default:
669 major = 0;
670 minor = 9;
672 gl_info->driver_version = MAKEDWORD_VERSION(major, minor);
673 TRACE_(d3d_caps)("found driver version (%s)->%i.%i->(0x%08x)\n", debugstr_a(gl_string), major, minor, gl_info->driver_version);
674 /* Current Windows drivers have versions like 6.14.... (some older have an earlier version) */
675 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
676 } else {
677 FIXME("OpenGL driver did not return version information\n");
678 gl_info->driver_version = MAKEDWORD_VERSION(0, 0);
679 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
682 TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
685 * Initialize openGL extension related variables
686 * with Default values
688 memset(&gl_info->supported, 0, sizeof(gl_info->supported));
689 gl_info->max_buffers = 1;
690 gl_info->max_textures = 1;
691 gl_info->max_texture_stages = 1;
692 gl_info->max_fragment_samplers = 1;
693 gl_info->max_vertex_samplers = 0;
694 gl_info->max_combined_samplers = 0;
695 gl_info->max_sampler_stages = 1;
696 gl_info->ps_arb_version = PS_VERSION_NOT_SUPPORTED;
697 gl_info->ps_arb_max_temps = 0;
698 gl_info->ps_arb_max_instructions = 0;
699 gl_info->vs_arb_version = VS_VERSION_NOT_SUPPORTED;
700 gl_info->vs_arb_max_temps = 0;
701 gl_info->vs_arb_max_instructions = 0;
702 gl_info->vs_nv_version = VS_VERSION_NOT_SUPPORTED;
703 gl_info->vs_ati_version = VS_VERSION_NOT_SUPPORTED;
704 gl_info->vs_glsl_constantsF = 0;
705 gl_info->ps_glsl_constantsF = 0;
706 gl_info->vs_arb_constantsF = 0;
707 gl_info->ps_arb_constantsF = 0;
709 /* Retrieve opengl defaults */
710 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
711 gl_info->max_clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
712 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
714 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
715 gl_info->max_lights = gl_max;
716 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
718 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
719 gl_info->max_texture_size = gl_max;
720 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
722 glGetFloatv(GL_POINT_SIZE_RANGE, gl_floatv);
723 gl_info->max_pointsizemin = gl_floatv[0];
724 gl_info->max_pointsize = gl_floatv[1];
725 TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
727 glGetIntegerv(GL_AUX_BUFFERS, &gl_max);
728 gl_info->max_aux_buffers = gl_max;
729 TRACE_(d3d_caps)("Offscreen rendering support - number of aux buffers=%d\n", gl_max);
731 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
732 GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
733 TRACE_(d3d_caps)("GL_Extensions reported:\n");
735 if (NULL == GL_Extensions) {
736 ERR(" GL_Extensions returns NULL\n");
737 } else {
738 while (*GL_Extensions != 0x00) {
739 const char *Start;
740 char ThisExtn[256];
741 size_t len;
743 while (isspace(*GL_Extensions)) GL_Extensions++;
744 Start = GL_Extensions;
745 while (!isspace(*GL_Extensions) && *GL_Extensions != 0x00) {
746 GL_Extensions++;
749 len = GL_Extensions - Start;
750 if (len == 0 || len >= sizeof(ThisExtn))
751 continue;
753 memcpy(ThisExtn, Start, len);
754 ThisExtn[len] = '\0';
755 TRACE_(d3d_caps)("- %s\n", ThisExtn);
757 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
758 if (!strcmp(ThisExtn, EXTENSION_MAP[i].extension_string)) {
759 TRACE_(d3d_caps)(" FOUND: %s support\n", EXTENSION_MAP[i].extension_string);
760 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
761 break;
765 /* Now work out what GL support this card really has */
766 #define USE_GL_FUNC(type, pfn, ext, replace) { \
767 DWORD ver = ver_for_ext(ext); \
768 if(gl_info->supported[ext]) gl_info->pfn = (type) pwglGetProcAddress(#pfn); \
769 else if(ver && ver <= gl_info->gl_version) gl_info->pfn = (type) pwglGetProcAddress(#replace); \
770 else gl_info->pfn = NULL; \
772 GL_EXT_FUNCS_GEN;
773 #undef USE_GL_FUNC
775 #define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type) pwglGetProcAddress(#pfn);
776 WGL_EXT_FUNCS_GEN;
777 #undef USE_GL_FUNC
779 /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
780 * loading the functions, otherwise the code above will load the extension entry points instead of the
781 * core functions, which may not work
783 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
784 if (gl_info->supported[EXTENSION_MAP[i].extension] == FALSE &&
785 EXTENSION_MAP[i].version <= gl_info->gl_version && EXTENSION_MAP[i].version) {
786 TRACE_(d3d_caps)(" GL CORE: %s support\n", EXTENSION_MAP[i].extension_string);
787 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
791 if (gl_info->supported[APPLE_FENCE]) {
792 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
793 * The apple extension interacts with some other apple exts. Disable the NV
794 * extension if the apple one is support to prevent confusion in other parts
795 * of the code
797 gl_info->supported[NV_FENCE] = FALSE;
799 if (gl_info->supported[APPLE_FLOAT_PIXELS]) {
800 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
802 * The enums are the same:
803 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881A
804 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881B
805 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
806 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
807 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140B
809 if(!gl_info->supported[ARB_TEXTURE_FLOAT]) {
810 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels\n");
811 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
813 if(!gl_info->supported[ARB_HALF_FLOAT_PIXEL]) {
814 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels\n");
815 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
818 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) {
819 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
820 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
822 if (gl_info->supported[NV_TEXTURE_SHADER2]) {
823 /* GL_ATI_envmap_bumpmap won't play nice with texture shaders, so disable it
824 * Won't occur in any real world situation though
826 gl_info->supported[ATI_ENVMAP_BUMPMAP] = FALSE;
827 if(gl_info->supported[NV_REGISTER_COMBINERS]) {
828 /* Also disable ATI_FRAGMENT_SHADER if register combienrs and texture_shader2
829 * are supported. The nv extensions provide the same functionality as the
830 * ATI one, and a bit more(signed pixelformats)
832 gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
835 if (gl_info->supported[ARB_DRAW_BUFFERS]) {
836 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
837 gl_info->max_buffers = gl_max;
838 TRACE_(d3d_caps)("Max draw buffers: %u\n", gl_max);
840 if (gl_info->supported[ARB_MULTITEXTURE]) {
841 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
842 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
843 TRACE_(d3d_caps)("Max textures: %d\n", gl_info->max_textures);
845 if (gl_info->supported[NV_REGISTER_COMBINERS]) {
846 GLint tmp;
847 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &tmp);
848 gl_info->max_texture_stages = min(MAX_TEXTURES, tmp);
849 } else {
850 gl_info->max_texture_stages = min(MAX_TEXTURES, gl_max);
852 TRACE_(d3d_caps)("Max texture stages: %d\n", gl_info->max_texture_stages);
854 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
855 GLint tmp;
856 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
857 gl_info->max_fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
858 } else {
859 gl_info->max_fragment_samplers = max(gl_info->max_fragment_samplers, gl_max);
861 TRACE_(d3d_caps)("Max fragment samplers: %d\n", gl_info->max_fragment_samplers);
863 if (gl_info->supported[ARB_VERTEX_SHADER]) {
864 GLint tmp;
865 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
866 gl_info->max_vertex_samplers = tmp;
867 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
868 gl_info->max_combined_samplers = tmp;
870 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
871 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
872 * an issue because then the sampler setup only depends on the two shaders. If a pixel
873 * shader is used with fixed function vertex processing we're fine too because fixed function
874 * vertex processing doesn't use any samplers. If fixed function fragment processing is
875 * used we have to make sure that all vertex sampler setups are valid together with all
876 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
877 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
878 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
879 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
880 * a fixed function pipeline anymore.
882 * So this is just a check to check that our assumption holds true. If not, write a warning
883 * and reduce the number of vertex samplers or probably disable vertex texture fetch.
885 if(gl_info->max_vertex_samplers &&
886 MAX_TEXTURES + gl_info->max_vertex_samplers > gl_info->max_combined_samplers) {
887 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers\n",
888 gl_info->max_vertex_samplers, gl_info->max_combined_samplers);
889 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers\n");
890 if( gl_info->max_combined_samplers > MAX_TEXTURES )
891 gl_info->max_vertex_samplers =
892 gl_info->max_combined_samplers - MAX_TEXTURES;
893 else
894 gl_info->max_vertex_samplers = 0;
896 } else {
897 gl_info->max_combined_samplers = gl_info->max_fragment_samplers;
899 TRACE_(d3d_caps)("Max vertex samplers: %u\n", gl_info->max_vertex_samplers);
900 TRACE_(d3d_caps)("Max combined samplers: %u\n", gl_info->max_combined_samplers);
902 if (gl_info->supported[ARB_VERTEX_BLEND]) {
903 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
904 gl_info->max_blends = gl_max;
905 TRACE_(d3d_caps)("Max blends: %u\n", gl_info->max_blends);
907 if (gl_info->supported[EXT_TEXTURE3D]) {
908 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
909 gl_info->max_texture3d_size = gl_max;
910 TRACE_(d3d_caps)("Max texture3D size: %d\n", gl_info->max_texture3d_size);
912 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC]) {
913 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
914 gl_info->max_anisotropy = gl_max;
915 TRACE_(d3d_caps)("Max anisotropy: %d\n", gl_info->max_anisotropy);
917 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
918 gl_info->ps_arb_version = PS_VERSION_11;
919 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
920 gl_info->ps_arb_constantsF = gl_max;
921 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d\n", gl_info->ps_arb_constantsF);
922 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
923 gl_info->ps_arb_max_temps = gl_max;
924 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d\n", gl_info->ps_arb_max_temps);
925 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
926 gl_info->ps_arb_max_instructions = gl_max;
927 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d\n", gl_info->ps_arb_max_instructions);
929 if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
930 gl_info->vs_arb_version = VS_VERSION_11;
931 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
932 gl_info->vs_arb_constantsF = gl_max;
933 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d\n", gl_info->vs_arb_constantsF);
934 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
935 gl_info->vs_arb_max_temps = gl_max;
936 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d\n", gl_info->vs_arb_max_temps);
937 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
938 gl_info->vs_arb_max_instructions = gl_max;
939 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d\n", gl_info->vs_arb_max_instructions);
941 gl_info->arb_vs_offset_limit = test_arb_vs_offset_limit(gl_info);
943 if (gl_info->supported[ARB_VERTEX_SHADER]) {
944 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
945 gl_info->vs_glsl_constantsF = gl_max / 4;
946 TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u\n", gl_info->vs_glsl_constantsF);
948 if (gl_info->supported[ARB_FRAGMENT_SHADER]) {
949 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
950 gl_info->ps_glsl_constantsF = gl_max / 4;
951 TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u\n", gl_info->ps_glsl_constantsF);
952 glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
953 gl_info->max_glsl_varyings = gl_max;
954 TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings)\n", gl_max, gl_max / 4);
956 if (gl_info->supported[EXT_VERTEX_SHADER]) {
957 gl_info->vs_ati_version = VS_VERSION_11;
959 if (gl_info->supported[NV_VERTEX_PROGRAM3]) {
960 gl_info->vs_nv_version = VS_VERSION_30;
961 } else if (gl_info->supported[NV_VERTEX_PROGRAM2]) {
962 gl_info->vs_nv_version = VS_VERSION_20;
963 } else if (gl_info->supported[NV_VERTEX_PROGRAM1_1]) {
964 gl_info->vs_nv_version = VS_VERSION_11;
965 } else if (gl_info->supported[NV_VERTEX_PROGRAM]) {
966 gl_info->vs_nv_version = VS_VERSION_10;
968 if (gl_info->supported[NV_FRAGMENT_PROGRAM2]) {
969 gl_info->ps_nv_version = PS_VERSION_30;
970 } else if (gl_info->supported[NV_FRAGMENT_PROGRAM]) {
971 gl_info->ps_nv_version = PS_VERSION_20;
973 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT]) {
974 glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->max_shininess);
975 } else {
976 gl_info->max_shininess = 128.0;
978 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO]) {
979 /* If we have full NP2 texture support, disable GL_ARB_texture_rectangle because we will never use it.
980 * This saves a few redundant glDisable calls
982 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
984 if(gl_info->supported[ATI_FRAGMENT_SHADER]) {
985 /* Disable NV_register_combiners and fragment shader if this is supported.
986 * generally the NV extensions are prefered over the ATI one, and this
987 * extension is disabled if register_combiners and texture_shader2 are both
988 * supported. So we reach this place only if we have incomplete NV dxlevel 8
989 * fragment processing support
991 gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
992 gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
993 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
994 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
995 gl_info->supported[NV_TEXTURE_SHADER3] = FALSE;
999 checkGLcall("extension detection\n");
1001 /* In some cases the number of texture stages can be larger than the number
1002 * of samplers. The GF4 for example can use only 2 samplers (no fragment
1003 * shaders), but 8 texture stages (register combiners). */
1004 gl_info->max_sampler_stages = max(gl_info->max_fragment_samplers, gl_info->max_texture_stages);
1006 /* We can only use ORM_FBO when the hardware supports it. */
1007 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && !gl_info->supported[EXT_FRAMEBUFFER_OBJECT]) {
1008 WARN_(d3d_caps)("GL_EXT_framebuffer_object not supported, falling back to PBuffer offscreen rendering mode.\n");
1009 wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
1012 /* MRTs are currently only supported when FBOs are used. */
1013 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) {
1014 gl_info->max_buffers = 1;
1017 /* Below is a list of Nvidia and ATI GPUs. Both vendors have dozens of different GPUs with roughly the same
1018 * features. In most cases GPUs from a certain family differ in clockspeeds, the amount of video memory and
1019 * in case of the latest videocards in the number of pixel/vertex pipelines.
1021 * A Direct3D device object contains the PCI id (vendor + device) of the videocard which is used for
1022 * rendering. Various games use this information to get a rough estimation of the features of the card
1023 * and some might use it for enabling 3d effects only on certain types of videocards. In some cases
1024 * games might even use it to work around bugs which happen on certain videocards/driver combinations.
1025 * The problem is that OpenGL only exposes a rendering string containing the name of the videocard and
1026 * not the PCI id.
1028 * Various games depend on the PCI id, so somehow we need to provide one. A simple option is to parse
1029 * the renderer string and translate this to the right PCI id. This is a lot of work because there are more
1030 * than 200 GPUs just for Nvidia. Various cards share the same renderer string, so the amount of code might
1031 * be 'small' but there are quite a number of exceptions which would make this a pain to maintain.
1032 * Another way would be to query the PCI id from the operating system (assuming this is the videocard which
1033 * is used for rendering which is not always the case). This would work but it is not very portable. Second
1034 * it would not work well in, let's say, a remote X situation in which the amount of 3d features which can be used
1035 * is limited.
1037 * As said most games only use the PCI id to get an indication of the capabilities of the card.
1038 * It doesn't really matter if the given id is the correct one if we return the id of a card with
1039 * similar 3d features.
1041 * The code below checks the OpenGL capabilities of a videocard and matches that to a certain level of
1042 * Direct3D functionality. Once a card passes the Direct3D9 check, we know that the card (in case of Nvidia)
1043 * is at least a GeforceFX. To give a better estimate we do a basic check on the renderer string but if that
1044 * won't pass we return a default card. This way is better than maintaining a full card database as even
1045 * without a full database we can return a card with similar features. Second the size of the database
1046 * can be made quite small because when you know what type of 3d functionality a card has, you know to which
1047 * GPU family the GPU must belong. Because of this you only have to check a small part of the renderer string
1048 * to distinguishes between different models from that family.
1050 * The code also selects a default amount of video memory which we will use for an estimation of the amount
1051 * of free texture memory. In case of real D3D the amount of texture memory includes video memory and system
1052 * memory (to be specific AGP memory or in case of PCIE TurboCache/HyperMemory). We don't know how much
1053 * system memory can be addressed by the system but we can make a reasonable estimation about the amount of
1054 * video memory. If the value is slightly wrong it doesn't matter as we didn't include AGP-like memory which
1055 * makes the amount of addressable memory higher and second OpenGL isn't that critical it moves to system
1056 * memory behind our backs if really needed.
1057 * Note that the amount of video memory can be overruled using a registry setting.
1059 switch (gl_info->gl_vendor) {
1060 case VENDOR_NVIDIA:
1061 /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1062 * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1064 if(WINE_D3D9_CAPABLE(gl_info) && (gl_info->vs_nv_version == VS_VERSION_30)) {
1065 /* Geforce8 - highend */
1066 if (strstr(gl_info->gl_renderer, "8800")) {
1067 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8800GTS;
1068 vidmem = 320; /* The 8800GTS uses 320MB, a 8800GTX can have 768MB */
1070 /* Geforce8 - midend mobile */
1071 else if(strstr(gl_info->gl_renderer, "8600 M")) {
1072 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600MGT;
1073 vidmem = 512;
1075 /* Geforce8 - midend */
1076 else if(strstr(gl_info->gl_renderer, "8600") ||
1077 strstr(gl_info->gl_renderer, "8700"))
1079 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600GT;
1080 vidmem = 256;
1082 /* Geforce8 - lowend */
1083 else if(strstr(gl_info->gl_renderer, "8300") ||
1084 strstr(gl_info->gl_renderer, "8400") ||
1085 strstr(gl_info->gl_renderer, "8500"))
1087 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8300GS;
1088 vidmem = 128; /* 128-256MB for a 8300, 256-512MB for a 8400 */
1090 /* Geforce7 - highend */
1091 else if(strstr(gl_info->gl_renderer, "7800") ||
1092 strstr(gl_info->gl_renderer, "7900") ||
1093 strstr(gl_info->gl_renderer, "7950") ||
1094 strstr(gl_info->gl_renderer, "Quadro FX 4") ||
1095 strstr(gl_info->gl_renderer, "Quadro FX 5"))
1097 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7800GT;
1098 vidmem = 256; /* A 7800GT uses 256MB while highend 7900 cards can use 512MB */
1100 /* Geforce7 midend */
1101 else if(strstr(gl_info->gl_renderer, "7600") ||
1102 strstr(gl_info->gl_renderer, "7700")) {
1103 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7600;
1104 vidmem = 256; /* The 7600 uses 256-512MB */
1105 /* Geforce7 lower medium */
1106 } else if(strstr(gl_info->gl_renderer, "7400")) {
1107 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7400;
1108 vidmem = 256; /* The 7400 uses 256-512MB */
1110 /* Geforce7 lowend */
1111 else if(strstr(gl_info->gl_renderer, "7300")) {
1112 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7300;
1113 vidmem = 256; /* Mac Pros with this card have 256 MB */
1115 /* Geforce6 highend */
1116 else if(strstr(gl_info->gl_renderer, "6800"))
1118 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6800;
1119 vidmem = 128; /* The 6800 uses 128-256MB, the 7600 uses 256-512MB */
1121 /* Geforce6 - midend */
1122 else if(strstr(gl_info->gl_renderer, "6600") ||
1123 strstr(gl_info->gl_renderer, "6610") ||
1124 strstr(gl_info->gl_renderer, "6700"))
1126 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6600GT;
1127 vidmem = 128; /* A 6600GT has 128-256MB */
1129 /* Geforce6/7 lowend */
1130 else {
1131 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
1132 vidmem = 64; /* */
1134 } else if(WINE_D3D9_CAPABLE(gl_info)) {
1135 /* GeforceFX - highend */
1136 if (strstr(gl_info->gl_renderer, "5800") ||
1137 strstr(gl_info->gl_renderer, "5900") ||
1138 strstr(gl_info->gl_renderer, "5950") ||
1139 strstr(gl_info->gl_renderer, "Quadro FX"))
1141 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5800;
1142 vidmem = 256; /* 5800-5900 cards use 256MB */
1144 /* GeforceFX - midend */
1145 else if(strstr(gl_info->gl_renderer, "5600") ||
1146 strstr(gl_info->gl_renderer, "5650") ||
1147 strstr(gl_info->gl_renderer, "5700") ||
1148 strstr(gl_info->gl_renderer, "5750"))
1150 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1151 vidmem = 128; /* A 5600 uses 128-256MB */
1153 /* GeforceFX - lowend */
1154 else {
1155 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1156 vidmem = 64; /* Normal FX5200 cards use 64-256MB; laptop (non-standard) can have less */
1158 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1159 if (strstr(gl_info->gl_renderer, "GeForce4 Ti") || strstr(gl_info->gl_renderer, "Quadro4")) {
1160 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1161 vidmem = 64; /* Geforce4 Ti cards have 64-128MB */
1163 else {
1164 gl_info->gl_card = CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1165 vidmem = 64; /* Geforce3 cards have 64-128MB */
1167 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1168 if (strstr(gl_info->gl_renderer, "GeForce4 MX")) {
1169 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1170 vidmem = 64; /* Most Geforce4MX GPUs have at least 64MB of memory, some early models had 32MB but most have 64MB or even 128MB */
1172 else if(strstr(gl_info->gl_renderer, "GeForce2 MX") || strstr(gl_info->gl_renderer, "Quadro2 MXR")) {
1173 gl_info->gl_card = CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1174 vidmem = 32; /* Geforce2MX GPUs have 32-64MB of video memory */
1176 else if(strstr(gl_info->gl_renderer, "GeForce2") || strstr(gl_info->gl_renderer, "Quadro2")) {
1177 gl_info->gl_card = CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1178 vidmem = 32; /* Geforce2 GPUs have 32-64MB of video memory */
1180 else {
1181 gl_info->gl_card = CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1182 vidmem = 32; /* Most Geforce1 cards have 32MB, there are also some rare 16 and 64MB (Dell) models */
1184 } else {
1185 if (strstr(gl_info->gl_renderer, "TNT2")) {
1186 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1187 vidmem = 32; /* Most TNT2 boards have 32MB, though there are 16MB boards too */
1189 else {
1190 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1191 vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
1194 break;
1195 case VENDOR_ATI:
1196 if(WINE_D3D9_CAPABLE(gl_info)) {
1197 /* Radeon R6xx HD2900 - highend */
1198 if (strstr(gl_info->gl_renderer, "HD 2900")) {
1199 gl_info->gl_card = CARD_ATI_RADEON_HD2900;
1200 vidmem = 512; /* HD2900 uses 512-1024MB */
1202 /* Radeon R6xx HD2600- midend */
1203 else if (strstr(gl_info->gl_renderer, "HD 2600")) {
1204 gl_info->gl_card = CARD_ATI_RADEON_HD2600;
1205 vidmem = 256; /* HD2600 uses 256-512MB */
1207 /* Radeon R6xx HD2300/HD2400 - lowend */
1208 else if (strstr(gl_info->gl_renderer, "HD 2300") ||
1209 strstr(gl_info->gl_renderer, "HD 2400"))
1211 gl_info->gl_card = CARD_ATI_RADEON_HD2300;
1212 vidmem = 128; /* HD2300 uses at least 128MB, HD2400 uses 256MB */
1214 /* Radeon R5xx */
1215 else if (strstr(gl_info->gl_renderer, "X1600") ||
1216 strstr(gl_info->gl_renderer, "X1650") ||
1217 strstr(gl_info->gl_renderer, "X1800") ||
1218 strstr(gl_info->gl_renderer, "X1900") ||
1219 strstr(gl_info->gl_renderer, "X1950"))
1221 gl_info->gl_card = CARD_ATI_RADEON_X1600;
1222 vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
1224 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
1225 else if(strstr(gl_info->gl_renderer, "X700") ||
1226 strstr(gl_info->gl_renderer, "X800") ||
1227 strstr(gl_info->gl_renderer, "X850") ||
1228 strstr(gl_info->gl_renderer, "X1300") ||
1229 strstr(gl_info->gl_renderer, "X1400") ||
1230 strstr(gl_info->gl_renderer, "X1450") ||
1231 strstr(gl_info->gl_renderer, "X1550"))
1233 gl_info->gl_card = CARD_ATI_RADEON_X700;
1234 vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
1236 /* Radeon R3xx */
1237 else {
1238 gl_info->gl_card = CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
1239 vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
1241 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1242 gl_info->gl_card = CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
1243 vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
1244 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1245 gl_info->gl_card = CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
1246 vidmem = 32; /* There are models with up to 64MB */
1247 } else {
1248 gl_info->gl_card = CARD_ATI_RAGE_128PRO;
1249 vidmem = 16; /* There are 16-32MB models */
1251 break;
1252 case VENDOR_INTEL:
1253 if (strstr(gl_info->gl_renderer, "GMA 950")) {
1254 /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */
1255 gl_info->gl_card = CARD_INTEL_I945GM;
1256 vidmem = 64;
1257 } else if (strstr(gl_info->gl_renderer, "915GM")) {
1258 gl_info->gl_card = CARD_INTEL_I915GM;
1259 } else if (strstr(gl_info->gl_renderer, "915G")) {
1260 gl_info->gl_card = CARD_INTEL_I915G;
1261 } else if (strstr(gl_info->gl_renderer, "865G")) {
1262 gl_info->gl_card = CARD_INTEL_I865G;
1263 } else if (strstr(gl_info->gl_renderer, "855G")) {
1264 gl_info->gl_card = CARD_INTEL_I855G;
1265 } else if (strstr(gl_info->gl_renderer, "830G")) {
1266 gl_info->gl_card = CARD_INTEL_I830G;
1267 } else {
1268 gl_info->gl_card = CARD_INTEL_I915G;
1270 break;
1271 case VENDOR_MESA:
1272 case VENDOR_WINE:
1273 default:
1274 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice
1275 * for Nvidia was because the hardware and drivers they make are of good quality. This makes
1276 * them a good generic choice.
1278 gl_info->gl_vendor = VENDOR_NVIDIA;
1279 if(WINE_D3D9_CAPABLE(gl_info))
1280 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1281 else if(WINE_D3D8_CAPABLE(gl_info))
1282 gl_info->gl_card = CARD_NVIDIA_GEFORCE3;
1283 else if(WINE_D3D7_CAPABLE(gl_info))
1284 gl_info->gl_card = CARD_NVIDIA_GEFORCE;
1285 else if(WINE_D3D6_CAPABLE(gl_info))
1286 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT;
1287 else
1288 gl_info->gl_card = CARD_NVIDIA_RIVA_128;
1290 TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card);
1292 /* If we have an estimate use it, else default to 64MB; */
1293 if(vidmem)
1294 gl_info->vidmem = vidmem*1024*1024; /* convert from MBs to bytes */
1295 else
1296 gl_info->vidmem = WINE_DEFAULT_VIDMEM;
1298 /* Load all the lookup tables
1299 TODO: It may be a good idea to make minLookup and maxLookup const and populate them in wined3d_private.h where they are declared */
1300 minLookup[WINELOOKUP_WARPPARAM] = WINED3DTADDRESS_WRAP;
1301 maxLookup[WINELOOKUP_WARPPARAM] = WINED3DTADDRESS_MIRRORONCE;
1303 minLookup[WINELOOKUP_MAGFILTER] = WINED3DTEXF_NONE;
1304 maxLookup[WINELOOKUP_MAGFILTER] = WINED3DTEXF_ANISOTROPIC;
1307 for (i = 0; i < MAX_LOOKUPS; i++) {
1308 stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
1311 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
1312 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
1313 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1314 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1315 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1316 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1317 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
1318 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
1319 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
1320 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
1322 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_NONE - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
1323 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_POINT - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
1324 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_LINEAR - minLookup[WINELOOKUP_MAGFILTER]] = GL_LINEAR;
1325 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_ANISOTROPIC - minLookup[WINELOOKUP_MAGFILTER]] =
1326 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR : GL_NEAREST;
1329 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_NONE] = GL_LINEAR;
1330 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_POINT] = GL_LINEAR;
1331 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_LINEAR] = GL_LINEAR;
1332 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_NONE] = GL_NEAREST;
1333 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_POINT] = GL_NEAREST_MIPMAP_NEAREST;
1334 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_LINEAR] = GL_NEAREST_MIPMAP_LINEAR;
1335 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_NONE] = GL_LINEAR;
1336 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_POINT] = GL_LINEAR_MIPMAP_NEAREST;
1337 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_LINEAR] = GL_LINEAR_MIPMAP_LINEAR;
1338 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_NONE] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ?
1339 GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1340 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_POINT] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR;
1341 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_LINEAR] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1343 /* TODO: config lookups */
1345 /* Make sure there's an active HDC else the WGL extensions will fail */
1346 hdc = pwglGetCurrentDC();
1347 if (hdc) {
1348 WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc));
1349 TRACE_(d3d_caps)("WGL_Extensions reported:\n");
1351 if (NULL == WGL_Extensions) {
1352 ERR(" WGL_Extensions returns NULL\n");
1353 } else {
1354 while (*WGL_Extensions != 0x00) {
1355 const char *Start;
1356 char ThisExtn[256];
1357 size_t len;
1359 while (isspace(*WGL_Extensions)) WGL_Extensions++;
1360 Start = WGL_Extensions;
1361 while (!isspace(*WGL_Extensions) && *WGL_Extensions != 0x00) {
1362 WGL_Extensions++;
1365 len = WGL_Extensions - Start;
1366 if (len == 0 || len >= sizeof(ThisExtn))
1367 continue;
1369 memcpy(ThisExtn, Start, len);
1370 ThisExtn[len] = '\0';
1371 TRACE_(d3d_caps)("- %s\n", ThisExtn);
1373 if (!strcmp(ThisExtn, "WGL_ARB_pbuffer")) {
1374 gl_info->supported[WGL_ARB_PBUFFER] = TRUE;
1375 TRACE_(d3d_caps)("FOUND: WGL_ARB_pbuffer support\n");
1380 LEAVE_GL();
1382 return return_value;
1384 #undef GLINFO_LOCATION
1386 /**********************************************************
1387 * IWineD3D implementation follows
1388 **********************************************************/
1390 static UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
1391 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1393 TRACE_(d3d_caps)("(%p): Reporting %d adapters\n", This, numAdapters);
1394 return numAdapters;
1397 static HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
1398 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1399 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
1400 return WINED3D_OK;
1403 static HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
1404 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1406 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
1407 return NULL;
1410 TRACE_(d3d_caps)("(%p)->(%d)\n", This, Adapter);
1411 return MonitorFromPoint(Adapters[Adapter].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
1414 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
1415 of the same bpp but different resolutions */
1417 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1418 static UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
1419 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1420 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
1422 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1423 return 0;
1426 /* TODO: Store modes per adapter and read it from the adapter structure */
1427 if (Adapter == 0) { /* Display */
1428 int i = 0;
1429 int j = 0;
1431 if (!DEBUG_SINGLE_MODE) {
1432 DEVMODEW DevModeW;
1434 ZeroMemory(&DevModeW, sizeof(DevModeW));
1435 DevModeW.dmSize = sizeof(DevModeW);
1436 while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
1437 j++;
1438 switch (Format)
1440 case WINED3DFMT_UNKNOWN:
1441 /* This is for D3D8, do not enumerate P8 here */
1442 if (DevModeW.dmBitsPerPel == 32 ||
1443 DevModeW.dmBitsPerPel == 16) i++;
1444 break;
1445 case WINED3DFMT_X8R8G8B8:
1446 if (DevModeW.dmBitsPerPel == 32) i++;
1447 break;
1448 case WINED3DFMT_R5G6B5:
1449 if (DevModeW.dmBitsPerPel == 16) i++;
1450 break;
1451 case WINED3DFMT_P8:
1452 if (DevModeW.dmBitsPerPel == 8) i++;
1453 break;
1454 default:
1455 /* Skip other modes as they do not match the requested format */
1456 break;
1459 } else {
1460 i = 1;
1461 j = 1;
1464 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
1465 return i;
1466 } else {
1467 FIXME_(d3d_caps)("Adapter not primary display\n");
1469 return 0;
1472 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1473 static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, WINED3DDISPLAYMODE* pMode) {
1474 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1475 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
1477 /* Validate the parameters as much as possible */
1478 if (NULL == pMode ||
1479 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
1480 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
1481 return WINED3DERR_INVALIDCALL;
1484 /* TODO: Store modes per adapter and read it from the adapter structure */
1485 if (Adapter == 0 && !DEBUG_SINGLE_MODE) { /* Display */
1486 DEVMODEW DevModeW;
1487 int ModeIdx = 0;
1488 int i = 0;
1489 int j = 0;
1491 ZeroMemory(&DevModeW, sizeof(DevModeW));
1492 DevModeW.dmSize = sizeof(DevModeW);
1494 /* If we are filtering to a specific format (D3D9), then need to skip
1495 all unrelated modes, but if mode is irrelevant (D3D8), then we can
1496 just count through the ones with valid bit depths */
1497 while ((i<=Mode) && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0)) {
1498 switch (Format)
1500 case WINED3DFMT_UNKNOWN:
1501 /* This is D3D8. Do not enumerate P8 here */
1502 if (DevModeW.dmBitsPerPel == 32 ||
1503 DevModeW.dmBitsPerPel == 16) i++;
1504 break;
1505 case WINED3DFMT_X8R8G8B8:
1506 if (DevModeW.dmBitsPerPel == 32) i++;
1507 break;
1508 case WINED3DFMT_R5G6B5:
1509 if (DevModeW.dmBitsPerPel == 16) i++;
1510 break;
1511 case WINED3DFMT_P8:
1512 if (DevModeW.dmBitsPerPel == 8) i++;
1513 break;
1514 default:
1515 /* Modes that don't match what we support can get an early-out */
1516 TRACE_(d3d_caps)("Searching for %s, returning D3DERR_INVALIDCALL\n", debug_d3dformat(Format));
1517 return WINED3DERR_INVALIDCALL;
1521 if (i == 0) {
1522 TRACE_(d3d_caps)("No modes found for format (%x - %s)\n", Format, debug_d3dformat(Format));
1523 return WINED3DERR_INVALIDCALL;
1525 ModeIdx = j - 1;
1527 /* Now get the display mode via the calculated index */
1528 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0)) {
1529 pMode->Width = DevModeW.dmPelsWidth;
1530 pMode->Height = DevModeW.dmPelsHeight;
1531 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1532 if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
1533 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1535 if (Format == WINED3DFMT_UNKNOWN) {
1536 pMode->Format = pixelformat_for_depth(DevModeW.dmBitsPerPel);
1537 } else {
1538 pMode->Format = Format;
1540 } else {
1541 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
1542 return WINED3DERR_INVALIDCALL;
1545 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
1546 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format),
1547 DevModeW.dmBitsPerPel);
1549 } else if (DEBUG_SINGLE_MODE) {
1550 /* Return one setting of the format requested */
1551 if (Mode > 0) return WINED3DERR_INVALIDCALL;
1552 pMode->Width = 800;
1553 pMode->Height = 600;
1554 pMode->RefreshRate = 60;
1555 pMode->Format = (Format == WINED3DFMT_UNKNOWN) ? WINED3DFMT_X8R8G8B8 : Format;
1556 } else {
1557 FIXME_(d3d_caps)("Adapter not primary display\n");
1560 return WINED3D_OK;
1563 static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, WINED3DDISPLAYMODE* pMode) {
1564 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1565 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
1567 if (NULL == pMode ||
1568 Adapter >= IWineD3D_GetAdapterCount(iface)) {
1569 return WINED3DERR_INVALIDCALL;
1572 if (Adapter == 0) { /* Display */
1573 int bpp = 0;
1574 DEVMODEW DevModeW;
1576 ZeroMemory(&DevModeW, sizeof(DevModeW));
1577 DevModeW.dmSize = sizeof(DevModeW);
1579 EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &DevModeW, 0);
1580 pMode->Width = DevModeW.dmPelsWidth;
1581 pMode->Height = DevModeW.dmPelsHeight;
1582 bpp = DevModeW.dmBitsPerPel;
1583 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1584 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
1586 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1589 pMode->Format = pixelformat_for_depth(bpp);
1590 } else {
1591 FIXME_(d3d_caps)("Adapter not primary display\n");
1594 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
1595 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
1596 return WINED3D_OK;
1599 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
1600 and fields being inserted in the middle, a new structure is used in place */
1601 static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
1602 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
1603 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1605 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %x, pId=%p)\n", This, Adapter, Flags, pIdentifier);
1607 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1608 return WINED3DERR_INVALIDCALL;
1611 /* Return the information requested */
1612 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
1613 strcpy(pIdentifier->Driver, Adapters[Adapter].driver);
1614 strcpy(pIdentifier->Description, Adapters[Adapter].description);
1616 /* Note dx8 doesn't supply a DeviceName */
1617 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
1618 pIdentifier->DriverVersion->u.HighPart = Adapters[Adapter].gl_info.driver_version_hipart;
1619 pIdentifier->DriverVersion->u.LowPart = Adapters[Adapter].gl_info.driver_version;
1620 *(pIdentifier->VendorId) = Adapters[Adapter].gl_info.gl_vendor;
1621 *(pIdentifier->DeviceId) = Adapters[Adapter].gl_info.gl_card;
1622 *(pIdentifier->SubSysId) = 0;
1623 *(pIdentifier->Revision) = 0;
1624 *pIdentifier->DeviceIdentifier = IID_D3DDEVICE_D3DUID;
1626 if (Flags & WINED3DENUM_NO_WHQL_LEVEL) {
1627 *(pIdentifier->WHQLLevel) = 0;
1628 } else {
1629 *(pIdentifier->WHQLLevel) = 1;
1632 return WINED3D_OK;
1635 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const WineD3D_PixelFormat *cfg, WINED3DFORMAT Format) {
1636 short redSize, greenSize, blueSize, alphaSize, colorBits;
1638 if(!cfg)
1639 return FALSE;
1641 if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */
1642 if(!getColorBits(Format, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits)) {
1643 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(Format));
1644 return FALSE;
1647 if(cfg->redSize < redSize)
1648 return FALSE;
1650 if(cfg->greenSize < greenSize)
1651 return FALSE;
1653 if(cfg->blueSize < blueSize)
1654 return FALSE;
1656 if(cfg->alphaSize < alphaSize)
1657 return FALSE;
1659 return TRUE;
1660 } else if(cfg->iPixelType == WGL_TYPE_RGBA_FLOAT_ARB) { /* Float RGBA formats; TODO: WGL_NV_float_buffer */
1661 if(Format == WINED3DFMT_R16F)
1662 return (cfg->redSize == 16 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1663 if(Format == WINED3DFMT_G16R16F)
1664 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1665 if(Format == WINED3DFMT_A16B16G16R16F)
1666 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 16 && cfg->alphaSize == 16);
1667 if(Format == WINED3DFMT_R32F)
1668 return (cfg->redSize == 32 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1669 if(Format == WINED3DFMT_G32R32F)
1670 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1671 if(Format == WINED3DFMT_A32B32G32R32F)
1672 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 32 && cfg->alphaSize == 32);
1673 } else {
1674 /* Probably a color index mode */
1675 return FALSE;
1678 return FALSE;
1681 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const WineD3D_PixelFormat *cfg, WINED3DFORMAT Format) {
1682 short depthSize, stencilSize;
1683 BOOL lockable = FALSE;
1685 if(!cfg)
1686 return FALSE;
1688 if(!getDepthStencilBits(Format, &depthSize, &stencilSize)) {
1689 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(Format));
1690 return FALSE;
1693 if((Format == WINED3DFMT_D16_LOCKABLE) || (Format == WINED3DFMT_D32F_LOCKABLE))
1694 lockable = TRUE;
1696 /* On some modern cards like the Geforce8/9 GLX doesn't offer some dephthstencil formats which D3D9 reports.
1697 * We can safely report 'compatible' formats (e.g. D24 can be used for D16) as long as we aren't dealing with
1698 * a lockable format. This also helps D3D <= 7 as they expect D16 which isn't offered without this on Geforce8 cards. */
1699 if(!(cfg->depthSize == depthSize || (!lockable && cfg->depthSize > depthSize)))
1700 return FALSE;
1702 if(cfg->stencilSize != stencilSize)
1703 return FALSE;
1705 return TRUE;
1708 static HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1709 WINED3DFORMAT AdapterFormat,
1710 WINED3DFORMAT RenderTargetFormat,
1711 WINED3DFORMAT DepthStencilFormat) {
1712 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1713 int nCfgs;
1714 WineD3D_PixelFormat *cfgs;
1715 int it;
1717 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
1718 This, Adapter,
1719 DeviceType, debug_d3ddevicetype(DeviceType),
1720 AdapterFormat, debug_d3dformat(AdapterFormat),
1721 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
1722 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
1724 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1725 TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning WINED3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
1726 return WINED3DERR_INVALIDCALL;
1729 cfgs = Adapters[Adapter].cfgs;
1730 nCfgs = Adapters[Adapter].nCfgs;
1731 for (it = 0; it < nCfgs; ++it) {
1732 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], RenderTargetFormat)) {
1733 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&cfgs[it], DepthStencilFormat)) {
1734 TRACE_(d3d_caps)("(%p) : Formats matched\n", This);
1735 return WINED3D_OK;
1739 WARN_(d3d_caps)("unsupported format pair: %s and %s\n", debug_d3dformat(RenderTargetFormat), debug_d3dformat(DepthStencilFormat));
1741 return WINED3DERR_NOTAVAILABLE;
1744 static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1745 WINED3DFORMAT SurfaceFormat,
1746 BOOL Windowed, WINED3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
1748 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1749 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
1750 This,
1751 Adapter,
1752 DeviceType, debug_d3ddevicetype(DeviceType),
1753 SurfaceFormat, debug_d3dformat(SurfaceFormat),
1754 Windowed,
1755 MultiSampleType,
1756 pQualityLevels);
1758 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1759 return WINED3DERR_INVALIDCALL;
1762 /* TODO: Store in Adapter structure */
1763 if (pQualityLevels != NULL) {
1764 static int s_single_shot = 0;
1765 if (!s_single_shot) {
1766 FIXME("Quality levels unsupported at present\n");
1767 s_single_shot = 1;
1769 *pQualityLevels = 1; /* Guess at a value! */
1772 if (WINED3DMULTISAMPLE_NONE == MultiSampleType) return WINED3D_OK;
1773 return WINED3DERR_NOTAVAILABLE;
1776 static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1777 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
1779 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1780 HRESULT hr = WINED3DERR_NOTAVAILABLE;
1781 UINT nmodes;
1783 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
1784 This,
1785 Adapter,
1786 DeviceType, debug_d3ddevicetype(DeviceType),
1787 DisplayFormat, debug_d3dformat(DisplayFormat),
1788 BackBufferFormat, debug_d3dformat(BackBufferFormat),
1789 Windowed);
1791 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1792 WARN_(d3d_caps)("Adapter >= IWineD3D_GetAdapterCount(iface), returning WINED3DERR_INVALIDCALL\n");
1793 return WINED3DERR_INVALIDCALL;
1796 /* The task of this function is to check whether a certain display / backbuffer format
1797 * combination is available on the given adapter. In fullscreen mode microsoft specified
1798 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
1799 * and display format should match exactly.
1800 * In windowed mode format conversion can occur and this depends on the driver. When format
1801 * conversion is done, this function should nevertheless fail and applications need to use
1802 * CheckDeviceFormatConversion.
1803 * At the moment we assume that fullscreen and windowed have the same capabilities */
1805 /* There are only 4 display formats */
1806 if(!((DisplayFormat == WINED3DFMT_R5G6B5) ||
1807 (DisplayFormat == WINED3DFMT_X1R5G5B5) ||
1808 (DisplayFormat == WINED3DFMT_X8R8G8B8) ||
1809 (DisplayFormat == WINED3DFMT_A2R10G10B10)))
1811 TRACE_(d3d_caps)("Format %s unsupported as display format\n", debug_d3dformat(DisplayFormat));
1812 return WINED3DERR_NOTAVAILABLE;
1815 /* If the requested DisplayFormat is not available, don't continue */
1816 nmodes = IWineD3DImpl_GetAdapterModeCount(iface, Adapter, DisplayFormat);
1817 if(!nmodes) {
1818 TRACE_(d3d_caps)("No available modes for display format %s\n", debug_d3dformat(DisplayFormat));
1819 return WINED3DERR_NOTAVAILABLE;
1822 /* Windowed mode allows you to specify WINED3DFMT_UNKNOWN for the backbufferformat, it means 'reuse' the display format for the backbuffer */
1823 if(!Windowed && BackBufferFormat == WINED3DFMT_UNKNOWN) {
1824 TRACE_(d3d_caps)("BackBufferFormat WINED3FMT_UNKNOWN not available in Windowed mode\n");
1825 return WINED3DERR_NOTAVAILABLE;
1828 /* In FULLSCREEN mode R5G6B5 can only be mixed with backbuffer format R5G6B5 */
1829 if( (DisplayFormat == WINED3DFMT_R5G6B5) && (BackBufferFormat != WINED3DFMT_R5G6B5) ) {
1830 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1831 return WINED3DERR_NOTAVAILABLE;
1834 /* In FULLSCREEN mode X1R5G5B5 can only be mixed with backbuffer format *1R5G5B5 */
1835 if( (DisplayFormat == WINED3DFMT_X1R5G5B5) && !((BackBufferFormat == WINED3DFMT_X1R5G5B5) || (BackBufferFormat == WINED3DFMT_A1R5G5B5)) ) {
1836 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1837 return WINED3DERR_NOTAVAILABLE;
1840 /* In FULLSCREEN mode X8R8G8B8 can only be mixed with backbuffer format *8R8G8B8 */
1841 if( (DisplayFormat == WINED3DFMT_X8R8G8B8) && !((BackBufferFormat == WINED3DFMT_X8R8G8B8) || (BackBufferFormat == WINED3DFMT_A8R8G8B8)) ) {
1842 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1843 return WINED3DERR_NOTAVAILABLE;
1846 /* A2R10G10B10 is only allowed in fullscreen mode and it can only be mixed with backbuffer format A2R10G10B10 */
1847 if( (DisplayFormat == WINED3DFMT_A2R10G10B10) && ((BackBufferFormat != WINED3DFMT_A2R10G10B10) || Windowed)) {
1848 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1849 return WINED3DERR_NOTAVAILABLE;
1852 /* Use CheckDeviceFormat to see if the BackBufferFormat is usable with the given DisplayFormat */
1853 hr = IWineD3DImpl_CheckDeviceFormat(iface, Adapter, DeviceType, DisplayFormat, WINED3DUSAGE_RENDERTARGET, WINED3DRTYPE_SURFACE, BackBufferFormat);
1854 if(FAILED(hr))
1855 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1857 return hr;
1861 #define GLINFO_LOCATION Adapters[Adapter].gl_info
1862 /* Check if we support bumpmapping for a format */
1863 static BOOL CheckBumpMapCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
1865 if(GL_SUPPORT(NV_REGISTER_COMBINERS) && GL_SUPPORT(NV_TEXTURE_SHADER2)) {
1866 switch (CheckFormat) {
1867 case WINED3DFMT_V8U8:
1868 TRACE_(d3d_caps)("[OK]\n");
1869 return TRUE;
1870 /* TODO: Other bump map formats */
1871 default:
1872 TRACE_(d3d_caps)("[FAILED]\n");
1873 return FALSE;
1876 if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP) || GL_SUPPORT(ATI_FRAGMENT_SHADER)) {
1877 switch (CheckFormat) {
1878 case WINED3DFMT_V8U8:
1879 TRACE_(d3d_caps)("[OK]\n");
1880 return TRUE;
1881 default:
1882 TRACE_(d3d_caps)("[FAILED]\n");
1883 return FALSE;
1886 TRACE_(d3d_caps)("[FAILED]\n");
1887 return FALSE;
1890 /* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
1891 static BOOL CheckDepthStencilCapability(UINT Adapter, WINED3DFORMAT DisplayFormat, WINED3DFORMAT DepthStencilFormat)
1893 int it=0;
1894 WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
1895 const GlPixelFormatDesc *glDesc;
1896 const StaticPixelFormatDesc *desc = getFormatDescEntry(DepthStencilFormat, &GLINFO_LOCATION, &glDesc);
1898 /* Fail if we weren't able to get a description of the format */
1899 if(!desc || !glDesc)
1900 return FALSE;
1902 /* Only allow depth/stencil formats */
1903 if(!(glDesc->Flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
1904 return FALSE;
1906 /* Walk through all WGL pixel formats to find a match */
1907 cfgs = Adapters[Adapter].cfgs;
1908 for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
1909 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], DisplayFormat)) {
1910 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&cfgs[it], DepthStencilFormat)) {
1911 return TRUE;
1916 return FALSE;
1919 static BOOL CheckFilterCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
1921 const GlPixelFormatDesc *glDesc;
1922 const StaticPixelFormatDesc *desc = getFormatDescEntry(CheckFormat, &GLINFO_LOCATION, &glDesc);
1924 /* Fail if we weren't able to get a description of the format */
1925 if(!desc || !glDesc)
1926 return FALSE;
1928 /* The flags entry of a format contains the filtering capability */
1929 if(glDesc->Flags & WINED3DFMT_FLAG_FILTERING)
1930 return TRUE;
1932 return FALSE;
1935 /* Check the render target capabilities of a format */
1936 static BOOL CheckRenderTargetCapability(WINED3DFORMAT AdapterFormat, WINED3DFORMAT CheckFormat)
1938 UINT Adapter = 0;
1939 const GlPixelFormatDesc *glDesc;
1940 const StaticPixelFormatDesc *desc = getFormatDescEntry(CheckFormat, &GLINFO_LOCATION, &glDesc);
1942 /* Fail if we weren't able to get a description of the format */
1943 if(!desc || !glDesc)
1944 return FALSE;
1946 /* Filter out non-RT formats */
1947 if(!(glDesc->Flags & WINED3DFMT_FLAG_RENDERTARGET))
1948 return FALSE;
1950 if(wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) {
1951 WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
1952 int it;
1953 short AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
1954 short CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
1956 getColorBits(AdapterFormat, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
1957 getColorBits(CheckFormat, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
1959 /* In backbuffer mode the front and backbuffer share the same WGL pixelformat.
1960 * The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */
1961 if(!((AdapterRed == CheckRed) && (AdapterGreen == CheckGreen) && (AdapterBlue == CheckBlue))) {
1962 TRACE_(d3d_caps)("[FAILED]\n");
1963 return FALSE;
1966 /* Check if there is a WGL pixel format matching the requirements, the format should also be window
1967 * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
1968 for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
1969 if (cfgs[it].windowDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], CheckFormat)) {
1970 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n", cfgs[it].iPixelFormat, debug_d3dformat(CheckFormat));
1971 return TRUE;
1974 } else if(wined3d_settings.offscreen_rendering_mode == ORM_PBUFFER) {
1975 /* We can propably use this function in FBO mode too on some drivers to get some basic indication of the capabilities. */
1976 WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
1977 int it;
1979 /* Check if there is a WGL pixel format matching the requirements, the pixel format should also be usable with pbuffers */
1980 for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
1981 if (cfgs[it].pbufferDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], CheckFormat)) {
1982 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n", cfgs[it].iPixelFormat, debug_d3dformat(CheckFormat));
1983 return TRUE;
1986 } else if(wined3d_settings.offscreen_rendering_mode == ORM_FBO){
1987 /* For now return TRUE for FBOs until we have some proper checks.
1988 * Note that this function will only be called when the format is around for texturing. */
1989 return TRUE;
1991 return FALSE;
1994 static BOOL CheckSrgbReadCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
1996 /* Check for supported sRGB formats (Texture loading and framebuffer) */
1997 if(!GL_SUPPORT(EXT_TEXTURE_SRGB)) {
1998 TRACE_(d3d_caps)("[FAILED] GL_EXT_texture_sRGB not supported\n");
1999 return FALSE;
2002 switch (CheckFormat) {
2003 case WINED3DFMT_A8R8G8B8:
2004 case WINED3DFMT_X8R8G8B8:
2005 case WINED3DFMT_A4R4G4B4:
2006 case WINED3DFMT_L8:
2007 case WINED3DFMT_A8L8:
2008 case WINED3DFMT_DXT1:
2009 case WINED3DFMT_DXT2:
2010 case WINED3DFMT_DXT3:
2011 case WINED3DFMT_DXT4:
2012 case WINED3DFMT_DXT5:
2013 TRACE_(d3d_caps)("[OK]\n");
2014 return TRUE;
2016 default:
2017 TRACE_(d3d_caps)("[FAILED] Gamma texture format %s not supported.\n", debug_d3dformat(CheckFormat));
2018 return FALSE;
2020 return FALSE;
2023 static BOOL CheckSrgbWriteCapability(UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT CheckFormat)
2025 /* Only offer SRGB writing on X8R8G8B8/A8R8G8B8 when we use ARB or GLSL shaders as we are
2026 * doing the color fixup in shaders.
2027 * Note Windows drivers (at least on the Geforce 8800) also offer this on R5G6B5. */
2028 if((CheckFormat == WINED3DFMT_X8R8G8B8) || (CheckFormat == WINED3DFMT_A8R8G8B8)) {
2029 int vs_selected_mode;
2030 int ps_selected_mode;
2031 select_shader_mode(&GLINFO_LOCATION, DeviceType, &ps_selected_mode, &vs_selected_mode);
2033 if((ps_selected_mode == SHADER_ARB) || (ps_selected_mode == SHADER_GLSL)) {
2034 TRACE_(d3d_caps)("[OK]\n");
2035 return TRUE;
2039 TRACE_(d3d_caps)("[FAILED] - no SRGB writing support on format=%s\n", debug_d3dformat(CheckFormat));
2040 return FALSE;
2043 /* Check if a format support blending in combination with pixel shaders */
2044 static BOOL CheckPostPixelShaderBlendingCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2046 const GlPixelFormatDesc *glDesc;
2047 const StaticPixelFormatDesc *desc = getFormatDescEntry(CheckFormat, &GLINFO_LOCATION, &glDesc);
2049 /* Fail if we weren't able to get a description of the format */
2050 if(!desc || !glDesc)
2051 return FALSE;
2053 /* The flags entry of a format contains the post pixel shader blending capability */
2054 if(glDesc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)
2055 return TRUE;
2057 return FALSE;
2060 /* Check if a texture format is supported on the given adapter */
2061 static BOOL CheckTextureCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2063 switch (CheckFormat) {
2065 /*****
2066 * supported: RGB(A) formats
2068 case WINED3DFMT_R8G8B8: /* Enable for dx7, blacklisted for 8 and 9 above */
2069 case WINED3DFMT_A8R8G8B8:
2070 case WINED3DFMT_X8R8G8B8:
2071 case WINED3DFMT_R5G6B5:
2072 case WINED3DFMT_X1R5G5B5:
2073 case WINED3DFMT_A1R5G5B5:
2074 case WINED3DFMT_A4R4G4B4:
2075 case WINED3DFMT_R3G3B2:
2076 case WINED3DFMT_A8:
2077 case WINED3DFMT_X4R4G4B4:
2078 case WINED3DFMT_A8B8G8R8:
2079 case WINED3DFMT_X8B8G8R8:
2080 case WINED3DFMT_A2R10G10B10:
2081 case WINED3DFMT_A2B10G10R10:
2082 case WINED3DFMT_G16R16:
2083 TRACE_(d3d_caps)("[OK]\n");
2084 return TRUE;
2086 /*****
2087 * supported: Palettized
2089 case WINED3DFMT_P8:
2090 TRACE_(d3d_caps)("[OK]\n");
2091 return TRUE;
2092 /* No Windows driver offers A8P8, so don't offer it either */
2093 case WINED3DFMT_A8P8:
2094 return FALSE;
2096 /*****
2097 * Supported: (Alpha)-Luminance
2099 case WINED3DFMT_L8:
2100 case WINED3DFMT_A8L8:
2101 case WINED3DFMT_A4L4:
2102 case WINED3DFMT_L16:
2103 TRACE_(d3d_caps)("[OK]\n");
2104 return TRUE;
2106 /* Depth/stencil is handled using checkDepthStencilCapability, return FALSE here */
2107 case WINED3DFMT_D16_LOCKABLE:
2108 case WINED3DFMT_D16:
2109 case WINED3DFMT_D15S1:
2110 case WINED3DFMT_D24X8:
2111 case WINED3DFMT_D24X4S4:
2112 case WINED3DFMT_D24S8:
2113 case WINED3DFMT_D24FS8:
2114 case WINED3DFMT_D32:
2115 case WINED3DFMT_D32F_LOCKABLE:
2116 return FALSE;
2118 /*****
2119 * Not supported everywhere(depends on GL_ATI_envmap_bumpmap or
2120 * GL_NV_texture_shader), but advertized to make apps happy.
2121 * Enable some because games often fail when they are not available
2122 * and are still playable even without bump mapping
2124 case WINED3DFMT_V8U8:
2125 if(GL_SUPPORT(NV_TEXTURE_SHADER) || GL_SUPPORT(ATI_ENVMAP_BUMPMAP) ||
2126 GL_SUPPORT(ATI_FRAGMENT_SHADER)) {
2127 return TRUE;
2129 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2130 return FALSE;
2132 case WINED3DFMT_X8L8V8U8:
2133 case WINED3DFMT_L6V5U5:
2134 WARN_(d3d_caps)("[FAILED]\n");
2135 return FALSE;
2137 case WINED3DFMT_Q8W8V8U8:
2138 case WINED3DFMT_V16U16:
2139 if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
2140 WARN_(d3d_caps)("[Not supported, but pretended to do]\n");
2141 return TRUE;
2143 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2144 return FALSE;
2146 /* Those are not advertized by the nvidia windows driver, and not
2147 * supported natively by GL_NV_texture_shader or GL_ATI_envmap_bumpmap.
2148 * WINED3DFMT_A2W10V10U10 could be loaded into shaders using the unsigned
2149 * ARGB format if needed
2151 case WINED3DFMT_W11V11U10:
2152 case WINED3DFMT_A2W10V10U10:
2153 WARN_(d3d_caps)("[FAILED]\n");
2154 return FALSE;
2156 case WINED3DFMT_DXT1:
2157 case WINED3DFMT_DXT2:
2158 case WINED3DFMT_DXT3:
2159 case WINED3DFMT_DXT4:
2160 case WINED3DFMT_DXT5:
2161 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
2162 TRACE_(d3d_caps)("[OK]\n");
2163 return TRUE;
2165 TRACE_(d3d_caps)("[FAILED]\n");
2166 return FALSE;
2169 /*****
2170 * Odd formats - not supported
2172 case WINED3DFMT_VERTEXDATA:
2173 case WINED3DFMT_INDEX16:
2174 case WINED3DFMT_INDEX32:
2175 case WINED3DFMT_Q16W16V16U16:
2176 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2177 return FALSE;
2179 /*****
2180 * WINED3DFMT_CxV8U8: Not supported right now
2182 case WINED3DFMT_CxV8U8:
2183 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2184 return FALSE;
2186 /* YUV formats, not supported for now */
2187 case WINED3DFMT_UYVY:
2188 case WINED3DFMT_YUY2:
2189 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2190 return FALSE;
2192 /* Not supported */
2193 case WINED3DFMT_A16B16G16R16:
2194 case WINED3DFMT_A8R3G3B2:
2195 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2196 return FALSE;
2198 /* Floating point formats */
2199 case WINED3DFMT_R16F:
2200 case WINED3DFMT_A16B16G16R16F:
2201 if(GL_SUPPORT(ARB_HALF_FLOAT_PIXEL)) {
2202 TRACE_(d3d_caps)("[OK]\n");
2203 return TRUE;
2205 TRACE_(d3d_caps)("[FAILED]\n");
2206 return FALSE;
2208 case WINED3DFMT_R32F:
2209 case WINED3DFMT_A32B32G32R32F:
2210 if (GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2211 TRACE_(d3d_caps)("[OK]\n");
2212 return TRUE;
2214 TRACE_(d3d_caps)("[FAILED]\n");
2215 return FALSE;
2217 case WINED3DFMT_G16R16F:
2218 case WINED3DFMT_G32R32F:
2219 TRACE_(d3d_caps)("[FAILED]\n");
2220 return FALSE;
2222 /* ATI instancing hack: Although ATI cards do not support Shader Model 3.0, they support
2223 * instancing. To query if the card supports instancing CheckDeviceFormat with the special format
2224 * MAKEFOURCC('I','N','S','T') is used. Should a (broken) app check for this provide a proper return value.
2225 * We can do instancing with all shader versions, but we need vertex shaders.
2227 * Additionally applications have to set the D3DRS_POINTSIZE render state to MAKEFOURCC('I','N','S','T') once
2228 * to enable instancing. WineD3D doesn't need that and just ignores it.
2230 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows.
2232 case WINEMAKEFOURCC('I','N','S','T'):
2233 TRACE("ATI Instancing check hack\n");
2234 if(GL_SUPPORT(ARB_VERTEX_PROGRAM) || GL_SUPPORT(ARB_VERTEX_SHADER)) {
2235 TRACE_(d3d_caps)("[OK]\n");
2236 return TRUE;
2238 TRACE_(d3d_caps)("[FAILED]\n");
2239 return FALSE;
2241 /* Some weird FOURCC formats */
2242 case WINED3DFMT_R8G8_B8G8:
2243 case WINED3DFMT_G8R8_G8B8:
2244 case WINED3DFMT_MULTI2_ARGB8:
2245 TRACE_(d3d_caps)("[FAILED]\n");
2246 return FALSE;
2248 case WINED3DFMT_UNKNOWN:
2249 return FALSE;
2251 default:
2252 ERR("Unhandled format=%s\n", debug_d3dformat(CheckFormat));
2253 break;
2255 return FALSE;
2258 static BOOL CheckVertexTextureCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2260 if (!GL_LIMITS(vertex_samplers)) {
2261 TRACE_(d3d_caps)("[FAILED]\n");
2262 return FALSE;
2265 switch (CheckFormat) {
2266 case WINED3DFMT_A32B32G32R32F:
2267 if (!GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2268 TRACE_(d3d_caps)("[FAILED]\n");
2269 return FALSE;
2271 TRACE_(d3d_caps)("[OK]\n");
2272 return TRUE;
2274 default:
2275 TRACE_(d3d_caps)("[FAILED]\n");
2276 return FALSE;
2278 return FALSE;
2281 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2282 WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat) {
2283 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2284 DWORD UsageCaps = 0;
2286 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%u,%s,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s))\n",
2287 This,
2288 Adapter,
2289 DeviceType, debug_d3ddevicetype(DeviceType),
2290 AdapterFormat, debug_d3dformat(AdapterFormat),
2291 Usage, debug_d3dusage(Usage), debug_d3dusagequery(Usage),
2292 RType, debug_d3dresourcetype(RType),
2293 CheckFormat, debug_d3dformat(CheckFormat));
2295 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2296 return WINED3DERR_INVALIDCALL;
2299 if(RType == WINED3DRTYPE_CUBETEXTURE) {
2300 /* Cubetexture allows:
2301 * - D3DUSAGE_AUTOGENMIPMAP
2302 * - D3DUSAGE_DEPTHSTENCIL
2303 * - D3DUSAGE_DYNAMIC
2304 * - D3DUSAGE_NONSECURE (d3d9ex)
2305 * - D3DUSAGE_RENDERTARGET
2306 * - D3DUSAGE_SOFTWAREPROCESSING
2308 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2309 /* Check if the texture format is around */
2310 if(CheckTextureCapability(Adapter, CheckFormat)) {
2311 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
2312 /* Check for automatic mipmap generation support */
2313 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2314 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
2315 } else {
2316 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUOTGEN instead of D3D_OK */
2317 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
2321 /* Always report dynamic locking */
2322 if(Usage & WINED3DUSAGE_DYNAMIC)
2323 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2325 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2326 if(CheckRenderTargetCapability(AdapterFormat, CheckFormat)) {
2327 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2328 } else {
2329 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2330 return WINED3DERR_NOTAVAILABLE;
2334 /* Always report software processing */
2335 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2336 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2338 /* Check QUERY_FILTER support */
2339 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2340 if(CheckFilterCapability(Adapter, CheckFormat)) {
2341 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2342 } else {
2343 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2344 return WINED3DERR_NOTAVAILABLE;
2348 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2349 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2350 if(CheckPostPixelShaderBlendingCapability(Adapter, CheckFormat)) {
2351 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2352 } else {
2353 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2354 return WINED3DERR_NOTAVAILABLE;
2358 /* Check QUERY_SRGBREAD support */
2359 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2360 if(CheckSrgbReadCapability(Adapter, CheckFormat)) {
2361 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2362 } else {
2363 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2364 return WINED3DERR_NOTAVAILABLE;
2368 /* Check QUERY_SRGBWRITE support */
2369 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2370 if(CheckSrgbWriteCapability(Adapter, DeviceType, CheckFormat)) {
2371 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2372 } else {
2373 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2374 return WINED3DERR_NOTAVAILABLE;
2378 /* Check QUERY_VERTEXTEXTURE support */
2379 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2380 if(CheckVertexTextureCapability(Adapter, CheckFormat)) {
2381 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2382 } else {
2383 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2384 return WINED3DERR_NOTAVAILABLE;
2387 } else {
2388 TRACE_(d3d_caps)("[FAILED] - Cube texture format not supported\n");
2389 return WINED3DERR_NOTAVAILABLE;
2391 } else {
2392 TRACE_(d3d_caps)("[FAILED] - No cube texture support\n");
2393 return WINED3DERR_NOTAVAILABLE;
2395 } else if(RType == WINED3DRTYPE_SURFACE) {
2396 /* Surface allows:
2397 * - D3DUSAGE_DEPTHSTENCIL
2398 * - D3DUSAGE_NONSECURE (d3d9ex)
2399 * - D3DUSAGE_RENDERTARGET
2402 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
2403 if(CheckDepthStencilCapability(Adapter, AdapterFormat, CheckFormat)) {
2404 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
2405 } else {
2406 TRACE_(d3d_caps)("[FAILED] - No depthstencil support\n");
2407 return WINED3DERR_NOTAVAILABLE;
2411 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2412 if(CheckRenderTargetCapability(AdapterFormat, CheckFormat)) {
2413 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2414 } else {
2415 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2416 return WINED3DERR_NOTAVAILABLE;
2419 } else if(RType == WINED3DRTYPE_TEXTURE) {
2420 /* Texture allows:
2421 * - D3DUSAGE_AUTOGENMIPMAP
2422 * - D3DUSAGE_DEPTHSTENCIL
2423 * - D3DUSAGE_DMAP
2424 * - D3DUSAGE_DYNAMIC
2425 * - D3DUSAGE_NONSECURE (d3d9ex)
2426 * - D3DUSAGE_RENDERTARGET
2427 * - D3DUSAGE_SOFTWAREPROCESSING
2428 * - D3DUSAGE_TEXTAPI (d3d9ex)
2431 /* Check if the texture format is around */
2432 if(CheckTextureCapability(Adapter, CheckFormat)) {
2433 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
2434 /* Check for automatic mipmap generation support */
2435 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2436 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
2437 } else {
2438 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUOTGEN instead of D3D_OK */
2439 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
2443 /* Always report dynamic locking */
2444 if(Usage & WINED3DUSAGE_DYNAMIC)
2445 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2447 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2448 if(CheckRenderTargetCapability(AdapterFormat, CheckFormat)) {
2449 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2450 } else {
2451 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2452 return WINED3DERR_NOTAVAILABLE;
2456 /* Always report software processing */
2457 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2458 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2460 /* Check QUERY_FILTER support */
2461 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2462 if(CheckFilterCapability(Adapter, CheckFormat)) {
2463 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2464 } else {
2465 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2466 return WINED3DERR_NOTAVAILABLE;
2470 /* Check QUERY_LEGACYBUMPMAP support */
2471 if(Usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP) {
2472 if(CheckBumpMapCapability(Adapter, CheckFormat)) {
2473 UsageCaps |= WINED3DUSAGE_QUERY_LEGACYBUMPMAP;
2474 } else {
2475 TRACE_(d3d_caps)("[FAILED] - No legacy bumpmap support\n");
2476 return WINED3DERR_NOTAVAILABLE;
2480 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2481 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2482 if(CheckPostPixelShaderBlendingCapability(Adapter, CheckFormat)) {
2483 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2484 } else {
2485 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2486 return WINED3DERR_NOTAVAILABLE;
2490 /* Check QUERY_SRGBREAD support */
2491 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2492 if(CheckSrgbReadCapability(Adapter, CheckFormat)) {
2493 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2494 } else {
2495 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2496 return WINED3DERR_NOTAVAILABLE;
2500 /* Check QUERY_SRGBWRITE support */
2501 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2502 if(CheckSrgbWriteCapability(Adapter, DeviceType, CheckFormat)) {
2503 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2504 } else {
2505 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2506 return WINED3DERR_NOTAVAILABLE;
2510 /* Check QUERY_VERTEXTEXTURE support */
2511 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2512 if(CheckVertexTextureCapability(Adapter, CheckFormat)) {
2513 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2514 } else {
2515 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2516 return WINED3DERR_NOTAVAILABLE;
2519 } else if(CheckDepthStencilCapability(Adapter, AdapterFormat, CheckFormat)) {
2520 if(Usage & WINED3DUSAGE_DEPTHSTENCIL)
2521 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
2522 } else {
2523 TRACE_(d3d_caps)("[FAILED] - Texture format not supported\n");
2524 return WINED3DERR_NOTAVAILABLE;
2526 } else if((RType == WINED3DRTYPE_VOLUME) || (RType == WINED3DRTYPE_VOLUMETEXTURE)) {
2527 /* Volume is to VolumeTexture what Surface is to Texture but its usage caps are not documented.
2528 * Most driver seem to offer (nearly) the same on Volume and VolumeTexture, so do that too.
2530 * Volumetexture allows:
2531 * - D3DUSAGE_DYNAMIC
2532 * - D3DUSAGE_NONSECURE (d3d9ex)
2533 * - D3DUSAGE_SOFTWAREPROCESSING
2536 /* Check volume texture and volume usage caps */
2537 if(GL_SUPPORT(EXT_TEXTURE3D)) {
2538 if(CheckTextureCapability(Adapter, CheckFormat) == FALSE) {
2539 TRACE_(d3d_caps)("[FAILED] - Format not supported\n");
2540 return WINED3DERR_NOTAVAILABLE;
2543 /* Always report dynamic locking */
2544 if(Usage & WINED3DUSAGE_DYNAMIC)
2545 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2547 /* Always report software processing */
2548 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2549 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2551 /* Check QUERY_FILTER support */
2552 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2553 if(CheckFilterCapability(Adapter, CheckFormat)) {
2554 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2555 } else {
2556 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2557 return WINED3DERR_NOTAVAILABLE;
2561 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2562 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2563 if(CheckPostPixelShaderBlendingCapability(Adapter, CheckFormat)) {
2564 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2565 } else {
2566 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2567 return WINED3DERR_NOTAVAILABLE;
2571 /* Check QUERY_SRGBREAD support */
2572 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2573 if(CheckSrgbReadCapability(Adapter, CheckFormat)) {
2574 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2575 } else {
2576 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2577 return WINED3DERR_NOTAVAILABLE;
2581 /* Check QUERY_SRGBWRITE support */
2582 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2583 if(CheckSrgbWriteCapability(Adapter, DeviceType, CheckFormat)) {
2584 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2585 } else {
2586 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2587 return WINED3DERR_NOTAVAILABLE;
2591 /* Check QUERY_VERTEXTEXTURE support */
2592 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2593 if(CheckVertexTextureCapability(Adapter, CheckFormat)) {
2594 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2595 } else {
2596 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2597 return WINED3DERR_NOTAVAILABLE;
2600 } else {
2601 TRACE_(d3d_caps)("[FAILED] - No volume texture support\n");
2602 return WINED3DERR_NOTAVAILABLE;
2605 /* Filter formats that need conversion; For one part, this conversion is unimplemented,
2606 * and volume textures are huge, so it would be a big performance hit. Unless we hit an
2607 * app needing one of those formats, don't advertize them to avoid leading apps into
2608 * temptation. The windows drivers don't support most of those formats on volumes anyway,
2609 * except of R32F.
2611 switch(CheckFormat) {
2612 case WINED3DFMT_P8:
2613 case WINED3DFMT_A4L4:
2614 case WINED3DFMT_R32F:
2615 case WINED3DFMT_R16F:
2616 case WINED3DFMT_X8L8V8U8:
2617 case WINED3DFMT_L6V5U5:
2618 case WINED3DFMT_G16R16:
2619 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2620 return WINED3DERR_NOTAVAILABLE;
2622 case WINED3DFMT_Q8W8V8U8:
2623 case WINED3DFMT_V16U16:
2624 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
2625 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2626 return WINED3DERR_NOTAVAILABLE;
2628 break;
2630 case WINED3DFMT_V8U8:
2631 if(!GL_SUPPORT(NV_TEXTURE_SHADER) || !GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
2632 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2633 return WINED3DERR_NOTAVAILABLE;
2635 break;
2637 case WINED3DFMT_DXT1:
2638 case WINED3DFMT_DXT2:
2639 case WINED3DFMT_DXT3:
2640 case WINED3DFMT_DXT4:
2641 case WINED3DFMT_DXT5:
2642 /* The GL_EXT_texture_compression_s3tc spec requires that loading an s3tc
2643 * compressed texture results in an error. While the D3D refrast does
2644 * support s3tc volumes, at least the nvidia windows driver does not, so
2645 * we're free not to support this format.
2647 TRACE_(d3d_caps)("[FAILED] - DXTn does not support 3D textures\n");
2648 return WINED3DERR_NOTAVAILABLE;
2650 default:
2651 /* Do nothing, continue with checking the format below */
2652 break;
2654 } else if((RType == WINED3DRTYPE_INDEXBUFFER) || (RType == WINED3DRTYPE_VERTEXBUFFER)){
2655 /* For instance vertexbuffer/indexbuffer aren't supported yet because no Windows drivers seem to offer it */
2656 TRACE_(d3d_caps)("Unhandled resource type D3DRTYPE_INDEXBUFFER / D3DRTYPE_VERTEXBUFFER\n");
2657 return WINED3DERR_NOTAVAILABLE;
2660 /* This format is nothing special and it is supported perfectly.
2661 * However, ati and nvidia driver on windows do not mark this format as
2662 * supported (tested with the dxCapsViewer) and pretending to
2663 * support this format uncovers a bug in Battlefield 1942 (fonts are missing)
2664 * So do the same as Windows drivers and pretend not to support it on dx8 and 9
2665 * Enable it on dx7. It will need additional checking on dx10 when we support it.
2667 if(This->dxVersion > 7 && CheckFormat == WINED3DFMT_R8G8B8) {
2668 TRACE_(d3d_caps)("[FAILED]\n");
2669 return WINED3DERR_NOTAVAILABLE;
2672 /* When the UsageCaps exactly matches Usage return WINED3D_OK except for the situation in which
2673 * WINED3DUSAGE_AUTOGENMIPMAP isn't around, then WINED3DOK_NOAUTOGEN is returned if all the other
2674 * usage flags match. */
2675 if(UsageCaps == Usage) {
2676 return WINED3D_OK;
2677 } else if((UsageCaps == (Usage & ~WINED3DUSAGE_AUTOGENMIPMAP)) && (Usage & WINED3DUSAGE_AUTOGENMIPMAP)){
2678 return WINED3DOK_NOAUTOGEN;
2679 } else {
2680 TRACE_(d3d_caps)("[FAILED] - Usage=%#08x requested for CheckFormat=%s and RType=%d but only %#08x is available\n", Usage, debug_d3dformat(CheckFormat), RType, UsageCaps);
2681 return WINED3DERR_NOTAVAILABLE;
2685 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2686 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
2687 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2689 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))\n",
2690 This,
2691 Adapter,
2692 DeviceType, debug_d3ddevicetype(DeviceType),
2693 SourceFormat, debug_d3dformat(SourceFormat),
2694 TargetFormat, debug_d3dformat(TargetFormat));
2695 return WINED3D_OK;
2698 static const shader_backend_t *select_shader_backend(UINT Adapter, WINED3DDEVTYPE DeviceType) {
2699 const shader_backend_t *ret;
2700 int vs_selected_mode;
2701 int ps_selected_mode;
2703 select_shader_mode(&GLINFO_LOCATION, DeviceType, &ps_selected_mode, &vs_selected_mode);
2704 if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) {
2705 ret = &glsl_shader_backend;
2706 } else if (vs_selected_mode == SHADER_ARB && ps_selected_mode != SHADER_NONE &&
2707 !GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
2708 ret = &atifs_shader_backend;
2709 } else if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) {
2710 ret = &arb_program_shader_backend;
2711 } else {
2712 ret = &none_shader_backend;
2714 return ret;
2717 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
2718 subset of a D3DCAPS9 structure. However, it has to come via a void *
2719 as the d3d8 interface cannot import the d3d9 header */
2720 static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
2722 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2723 int vs_selected_mode;
2724 int ps_selected_mode;
2725 struct shader_caps shader_caps;
2726 const shader_backend_t *shader_backend;
2728 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
2730 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2731 return WINED3DERR_INVALIDCALL;
2734 select_shader_mode(&Adapters[Adapter].gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
2736 /* This function should *not* be modifying GL caps
2737 * TODO: move the functionality where it belongs */
2738 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &Adapters[Adapter].gl_info);
2740 /* ------------------------------------------------
2741 The following fields apply to both d3d8 and d3d9
2742 ------------------------------------------------ */
2743 pCaps->DeviceType = (DeviceType == WINED3DDEVTYPE_HAL) ? WINED3DDEVTYPE_HAL : WINED3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
2744 pCaps->AdapterOrdinal = Adapter;
2746 pCaps->Caps = 0;
2747 pCaps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
2748 WINED3DCAPS2_FULLSCREENGAMMA |
2749 WINED3DCAPS2_DYNAMICTEXTURES;
2750 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2751 pCaps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
2753 pCaps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD;
2754 pCaps->PresentationIntervals = WINED3DPRESENT_INTERVAL_IMMEDIATE |
2755 WINED3DPRESENT_INTERVAL_ONE;
2757 pCaps->CursorCaps = WINED3DCURSORCAPS_COLOR |
2758 WINED3DCURSORCAPS_LOWRES;
2760 pCaps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
2761 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
2762 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
2763 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
2764 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
2765 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
2766 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
2767 WINED3DDEVCAPS_PUREDEVICE |
2768 WINED3DDEVCAPS_HWRASTERIZATION |
2769 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
2770 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
2771 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
2772 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
2773 WINED3DDEVCAPS_DRAWPRIMITIVES2EX |
2774 WINED3DDEVCAPS_RTPATCHES;
2776 pCaps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
2777 WINED3DPMISCCAPS_CULLCCW |
2778 WINED3DPMISCCAPS_CULLCW |
2779 WINED3DPMISCCAPS_COLORWRITEENABLE |
2780 WINED3DPMISCCAPS_CLIPTLVERTS |
2781 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
2782 WINED3DPMISCCAPS_MASKZ |
2783 WINED3DPMISCCAPS_BLENDOP;
2784 /* TODO:
2785 WINED3DPMISCCAPS_NULLREFERENCE
2786 WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS
2787 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
2788 WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
2789 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING
2790 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
2792 if(GL_SUPPORT(EXT_BLEND_EQUATION_SEPARATE) && GL_SUPPORT(EXT_BLEND_FUNC_SEPARATE))
2793 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
2795 pCaps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
2796 WINED3DPRASTERCAPS_PAT |
2797 WINED3DPRASTERCAPS_WFOG |
2798 WINED3DPRASTERCAPS_ZFOG |
2799 WINED3DPRASTERCAPS_FOGVERTEX |
2800 WINED3DPRASTERCAPS_FOGTABLE |
2801 WINED3DPRASTERCAPS_STIPPLE |
2802 WINED3DPRASTERCAPS_SUBPIXEL |
2803 WINED3DPRASTERCAPS_ZTEST |
2804 WINED3DPRASTERCAPS_SCISSORTEST |
2805 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
2806 WINED3DPRASTERCAPS_DEPTHBIAS;
2808 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2809 pCaps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY |
2810 WINED3DPRASTERCAPS_ZBIAS |
2811 WINED3DPRASTERCAPS_MIPMAPLODBIAS;
2813 if(GL_SUPPORT(NV_FOG_DISTANCE)) {
2814 pCaps->RasterCaps |= WINED3DPRASTERCAPS_FOGRANGE;
2816 /* FIXME Add:
2817 WINED3DPRASTERCAPS_COLORPERSPECTIVE
2818 WINED3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
2819 WINED3DPRASTERCAPS_ANTIALIASEDGES
2820 WINED3DPRASTERCAPS_ZBUFFERLESSHSR
2821 WINED3DPRASTERCAPS_WBUFFER */
2823 pCaps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
2824 WINED3DPCMPCAPS_EQUAL |
2825 WINED3DPCMPCAPS_GREATER |
2826 WINED3DPCMPCAPS_GREATEREQUAL |
2827 WINED3DPCMPCAPS_LESS |
2828 WINED3DPCMPCAPS_LESSEQUAL |
2829 WINED3DPCMPCAPS_NEVER |
2830 WINED3DPCMPCAPS_NOTEQUAL;
2832 pCaps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
2833 WINED3DPBLENDCAPS_BOTHSRCALPHA |
2834 WINED3DPBLENDCAPS_DESTALPHA |
2835 WINED3DPBLENDCAPS_DESTCOLOR |
2836 WINED3DPBLENDCAPS_INVDESTALPHA |
2837 WINED3DPBLENDCAPS_INVDESTCOLOR |
2838 WINED3DPBLENDCAPS_INVSRCALPHA |
2839 WINED3DPBLENDCAPS_INVSRCCOLOR |
2840 WINED3DPBLENDCAPS_ONE |
2841 WINED3DPBLENDCAPS_SRCALPHA |
2842 WINED3DPBLENDCAPS_SRCALPHASAT |
2843 WINED3DPBLENDCAPS_SRCCOLOR |
2844 WINED3DPBLENDCAPS_ZERO;
2846 pCaps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
2847 WINED3DPBLENDCAPS_DESTCOLOR |
2848 WINED3DPBLENDCAPS_INVDESTALPHA |
2849 WINED3DPBLENDCAPS_INVDESTCOLOR |
2850 WINED3DPBLENDCAPS_INVSRCALPHA |
2851 WINED3DPBLENDCAPS_INVSRCCOLOR |
2852 WINED3DPBLENDCAPS_ONE |
2853 WINED3DPBLENDCAPS_SRCALPHA |
2854 WINED3DPBLENDCAPS_SRCCOLOR |
2855 WINED3DPBLENDCAPS_ZERO;
2856 /* NOTE: WINED3DPBLENDCAPS_SRCALPHASAT is not supported as dest blend factor,
2857 * according to the glBlendFunc manpage
2859 * WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA are
2860 * legacy settings for srcblend only
2863 if( GL_SUPPORT(EXT_BLEND_COLOR)) {
2864 pCaps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
2865 pCaps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
2869 pCaps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
2870 WINED3DPCMPCAPS_EQUAL |
2871 WINED3DPCMPCAPS_GREATER |
2872 WINED3DPCMPCAPS_GREATEREQUAL |
2873 WINED3DPCMPCAPS_LESS |
2874 WINED3DPCMPCAPS_LESSEQUAL |
2875 WINED3DPCMPCAPS_NEVER |
2876 WINED3DPCMPCAPS_NOTEQUAL;
2878 pCaps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
2879 WINED3DPSHADECAPS_COLORGOURAUDRGB |
2880 WINED3DPSHADECAPS_ALPHAFLATBLEND |
2881 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
2882 WINED3DPSHADECAPS_COLORFLATRGB |
2883 WINED3DPSHADECAPS_FOGFLAT |
2884 WINED3DPSHADECAPS_FOGGOURAUD |
2885 WINED3DPSHADECAPS_SPECULARFLATRGB;
2887 pCaps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
2888 WINED3DPTEXTURECAPS_ALPHAPALETTE |
2889 WINED3DPTEXTURECAPS_BORDER |
2890 WINED3DPTEXTURECAPS_MIPMAP |
2891 WINED3DPTEXTURECAPS_PROJECTED |
2892 WINED3DPTEXTURECAPS_PERSPECTIVE;
2894 if( !GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
2895 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
2896 WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
2899 if( GL_SUPPORT(EXT_TEXTURE3D)) {
2900 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP |
2901 WINED3DPTEXTURECAPS_MIPVOLUMEMAP |
2902 WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
2905 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2906 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP |
2907 WINED3DPTEXTURECAPS_MIPCUBEMAP |
2908 WINED3DPTEXTURECAPS_CUBEMAP_POW2;
2912 pCaps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2913 WINED3DPTFILTERCAPS_MAGFPOINT |
2914 WINED3DPTFILTERCAPS_MINFLINEAR |
2915 WINED3DPTFILTERCAPS_MINFPOINT |
2916 WINED3DPTFILTERCAPS_MIPFLINEAR |
2917 WINED3DPTFILTERCAPS_MIPFPOINT |
2918 WINED3DPTFILTERCAPS_LINEAR |
2919 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2920 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2921 WINED3DPTFILTERCAPS_MIPLINEAR |
2922 WINED3DPTFILTERCAPS_MIPNEAREST |
2923 WINED3DPTFILTERCAPS_NEAREST;
2925 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2926 pCaps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
2927 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
2930 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2931 pCaps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2932 WINED3DPTFILTERCAPS_MAGFPOINT |
2933 WINED3DPTFILTERCAPS_MINFLINEAR |
2934 WINED3DPTFILTERCAPS_MINFPOINT |
2935 WINED3DPTFILTERCAPS_MIPFLINEAR |
2936 WINED3DPTFILTERCAPS_MIPFPOINT |
2937 WINED3DPTFILTERCAPS_LINEAR |
2938 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2939 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2940 WINED3DPTFILTERCAPS_MIPLINEAR |
2941 WINED3DPTFILTERCAPS_MIPNEAREST |
2942 WINED3DPTFILTERCAPS_NEAREST;
2944 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2945 pCaps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
2946 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
2948 } else
2949 pCaps->CubeTextureFilterCaps = 0;
2951 if (GL_SUPPORT(EXT_TEXTURE3D)) {
2952 pCaps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2953 WINED3DPTFILTERCAPS_MAGFPOINT |
2954 WINED3DPTFILTERCAPS_MINFLINEAR |
2955 WINED3DPTFILTERCAPS_MINFPOINT |
2956 WINED3DPTFILTERCAPS_MIPFLINEAR |
2957 WINED3DPTFILTERCAPS_MIPFPOINT |
2958 WINED3DPTFILTERCAPS_LINEAR |
2959 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2960 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2961 WINED3DPTFILTERCAPS_MIPLINEAR |
2962 WINED3DPTFILTERCAPS_MIPNEAREST |
2963 WINED3DPTFILTERCAPS_NEAREST;
2964 } else
2965 pCaps->VolumeTextureFilterCaps = 0;
2967 pCaps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
2968 WINED3DPTADDRESSCAPS_CLAMP |
2969 WINED3DPTADDRESSCAPS_WRAP;
2971 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
2972 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
2974 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
2975 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
2977 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
2978 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
2981 if (GL_SUPPORT(EXT_TEXTURE3D)) {
2982 pCaps->VolumeTextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
2983 WINED3DPTADDRESSCAPS_CLAMP |
2984 WINED3DPTADDRESSCAPS_WRAP;
2985 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
2986 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
2988 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
2989 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
2991 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
2992 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
2994 } else
2995 pCaps->VolumeTextureAddressCaps = 0;
2997 pCaps->LineCaps = WINED3DLINECAPS_TEXTURE |
2998 WINED3DLINECAPS_ZTEST;
2999 /* FIXME: Add
3000 WINED3DLINECAPS_BLEND
3001 WINED3DLINECAPS_ALPHACMP
3002 WINED3DLINECAPS_FOG */
3004 pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
3005 pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
3007 if(GL_SUPPORT(EXT_TEXTURE3D))
3008 pCaps->MaxVolumeExtent = GL_LIMITS(texture3d_size);
3009 else
3010 pCaps->MaxVolumeExtent = 0;
3012 pCaps->MaxTextureRepeat = 32768;
3013 pCaps->MaxTextureAspectRatio = GL_LIMITS(texture_size);
3014 pCaps->MaxVertexW = 1.0;
3016 pCaps->GuardBandLeft = 0;
3017 pCaps->GuardBandTop = 0;
3018 pCaps->GuardBandRight = 0;
3019 pCaps->GuardBandBottom = 0;
3021 pCaps->ExtentsAdjust = 0;
3023 pCaps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
3024 WINED3DSTENCILCAPS_INCRSAT |
3025 WINED3DSTENCILCAPS_INVERT |
3026 WINED3DSTENCILCAPS_KEEP |
3027 WINED3DSTENCILCAPS_REPLACE |
3028 WINED3DSTENCILCAPS_ZERO;
3029 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
3030 pCaps->StencilCaps |= WINED3DSTENCILCAPS_DECR |
3031 WINED3DSTENCILCAPS_INCR;
3033 if ( This->dxVersion > 8 &&
3034 ( GL_SUPPORT(EXT_STENCIL_TWO_SIDE) ||
3035 GL_SUPPORT(ATI_SEPARATE_STENCIL) ) ) {
3036 pCaps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
3039 pCaps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
3041 pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
3042 pCaps->MaxActiveLights = GL_LIMITS(lights);
3044 pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
3045 pCaps->MaxVertexBlendMatrixIndex = 0;
3047 pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
3048 pCaps->MaxPointSize = GL_LIMITS(pointsize);
3051 pCaps->VertexProcessingCaps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
3052 WINED3DVTXPCAPS_MATERIALSOURCE7 |
3053 WINED3DVTXPCAPS_POSITIONALLIGHTS |
3054 WINED3DVTXPCAPS_LOCALVIEWER |
3055 WINED3DVTXPCAPS_VERTEXFOG |
3056 WINED3DVTXPCAPS_TEXGEN;
3057 /* FIXME: Add
3058 D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
3060 pCaps->MaxPrimitiveCount = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
3061 pCaps->MaxVertexIndex = 0xFFFFF;
3062 pCaps->MaxStreams = MAX_STREAMS;
3063 pCaps->MaxStreamStride = 1024;
3065 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
3066 pCaps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET;
3067 /* TODO: VS3.0 needs at least D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET */
3068 pCaps->MaxNpatchTessellationLevel = 0;
3069 pCaps->MasterAdapterOrdinal = 0;
3070 pCaps->AdapterOrdinalInGroup = 0;
3071 pCaps->NumberOfAdaptersInGroup = 1;
3073 pCaps->NumSimultaneousRTs = GL_LIMITS(buffers);
3075 pCaps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
3076 WINED3DPTFILTERCAPS_MAGFPOINT |
3077 WINED3DPTFILTERCAPS_MINFLINEAR |
3078 WINED3DPTFILTERCAPS_MAGFLINEAR;
3079 pCaps->VertexTextureFilterCaps = 0;
3081 memset(&shader_caps, 0, sizeof(shader_caps));
3082 shader_backend = select_shader_backend(Adapter, DeviceType);
3083 shader_backend->shader_get_caps(DeviceType, &GLINFO_LOCATION, &shader_caps);
3085 /* Add shader misc caps. Only some of them belong to the shader parts of the pipeline */
3086 pCaps->PrimitiveMiscCaps |= shader_caps.PrimitiveMiscCaps;
3088 /* This takes care for disabling vertex shader or pixel shader caps while leaving the other one enabled.
3089 * Ignore shader model capabilities if disabled in config
3091 if(vs_selected_mode == SHADER_NONE) {
3092 TRACE_(d3d_caps)("Vertex shader disabled in config, reporting version 0.0\n");
3093 pCaps->VertexShaderVersion = WINED3DVS_VERSION(0,0);
3094 pCaps->MaxVertexShaderConst = 0;
3095 } else {
3096 pCaps->VertexShaderVersion = shader_caps.VertexShaderVersion;
3097 pCaps->MaxVertexShaderConst = shader_caps.MaxVertexShaderConst;
3100 if(ps_selected_mode == SHADER_NONE) {
3101 TRACE_(d3d_caps)("Pixel shader disabled in config, reporting version 0.0\n");
3102 pCaps->PixelShaderVersion = WINED3DPS_VERSION(0,0);
3103 pCaps->PixelShader1xMaxValue = 0.0;
3104 } else {
3105 pCaps->PixelShaderVersion = shader_caps.PixelShaderVersion;
3106 pCaps->PixelShader1xMaxValue = shader_caps.PixelShader1xMaxValue;
3109 pCaps->TextureOpCaps = shader_caps.TextureOpCaps;
3110 pCaps->MaxTextureBlendStages = shader_caps.MaxTextureBlendStages;
3111 pCaps->MaxSimultaneousTextures = shader_caps.MaxSimultaneousTextures;
3112 pCaps->VS20Caps = shader_caps.VS20Caps;
3113 pCaps->MaxVShaderInstructionsExecuted = shader_caps.MaxVShaderInstructionsExecuted;
3114 pCaps->MaxVertexShader30InstructionSlots= shader_caps.MaxVertexShader30InstructionSlots;
3115 pCaps->PS20Caps = shader_caps.PS20Caps;
3116 pCaps->MaxPShaderInstructionsExecuted = shader_caps.MaxPShaderInstructionsExecuted;
3117 pCaps->MaxPixelShader30InstructionSlots = shader_caps.MaxPixelShader30InstructionSlots;
3119 /* The following caps are shader specific, but they are things we cannot detect, or which
3120 * are the same among all shader models. So to avoid code duplication set the shader version
3121 * specific, but otherwise constant caps here
3123 if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(3,0)) {
3124 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
3125 use the VS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum VS3.0 value. */
3126 pCaps->VS20Caps.Caps = WINED3DVS20CAPS_PREDICATION;
3127 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
3128 pCaps->VS20Caps.NumTemps = max(32, GLINFO_LOCATION.vs_arb_max_temps);
3129 pCaps->VS20Caps.StaticFlowControlDepth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH ; /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
3131 pCaps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
3132 pCaps->MaxVertexShader30InstructionSlots = max(512, GLINFO_LOCATION.vs_arb_max_instructions);
3133 } else if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(2,0)) {
3134 pCaps->VS20Caps.Caps = 0;
3135 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
3136 pCaps->VS20Caps.NumTemps = max(12, GLINFO_LOCATION.vs_arb_max_temps);
3137 pCaps->VS20Caps.StaticFlowControlDepth = 1;
3139 pCaps->MaxVShaderInstructionsExecuted = 65535;
3140 pCaps->MaxVertexShader30InstructionSlots = 0;
3141 } else { /* VS 1.x */
3142 pCaps->VS20Caps.Caps = 0;
3143 pCaps->VS20Caps.DynamicFlowControlDepth = 0;
3144 pCaps->VS20Caps.NumTemps = 0;
3145 pCaps->VS20Caps.StaticFlowControlDepth = 0;
3147 pCaps->MaxVShaderInstructionsExecuted = 0;
3148 pCaps->MaxVertexShader30InstructionSlots = 0;
3151 if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(3,0)) {
3152 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
3153 use the PS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum PS 3.0 value. */
3155 /* 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 */
3156 pCaps->PS20Caps.Caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
3157 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
3158 WINED3DPS20CAPS_PREDICATION |
3159 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
3160 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
3161 pCaps->PS20Caps.DynamicFlowControlDepth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
3162 pCaps->PS20Caps.NumTemps = max(32, GLINFO_LOCATION.ps_arb_max_temps);
3163 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
3164 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
3166 pCaps->MaxPShaderInstructionsExecuted = 65535;
3167 pCaps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS, GLINFO_LOCATION.ps_arb_max_instructions);
3168 } else if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(2,0)) {
3169 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
3170 pCaps->PS20Caps.Caps = 0;
3171 pCaps->PS20Caps.DynamicFlowControlDepth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
3172 pCaps->PS20Caps.NumTemps = max(12, GLINFO_LOCATION.ps_arb_max_temps);
3173 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
3174 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
3176 pCaps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
3177 pCaps->MaxPixelShader30InstructionSlots = 0;
3178 } else { /* PS 1.x */
3179 pCaps->PS20Caps.Caps = 0;
3180 pCaps->PS20Caps.DynamicFlowControlDepth = 0;
3181 pCaps->PS20Caps.NumTemps = 0;
3182 pCaps->PS20Caps.StaticFlowControlDepth = 0;
3183 pCaps->PS20Caps.NumInstructionSlots = 0;
3185 pCaps->MaxPShaderInstructionsExecuted = 0;
3186 pCaps->MaxPixelShader30InstructionSlots = 0;
3189 if(pCaps->VertexShaderVersion >= WINED3DVS_VERSION(2,0)) {
3190 /* OpenGL supports all the formats below, perhaps not always
3191 * without conversion, but it supports them.
3192 * Further GLSL doesn't seem to have an official unsigned type so
3193 * don't advertise it yet as I'm not sure how we handle it.
3194 * We might need to add some clamping in the shader engine to
3195 * support it.
3196 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
3197 pCaps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
3198 WINED3DDTCAPS_UBYTE4N |
3199 WINED3DDTCAPS_SHORT2N |
3200 WINED3DDTCAPS_SHORT4N;
3201 if (GL_SUPPORT(NV_HALF_FLOAT)) {
3202 pCaps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
3203 WINED3DDTCAPS_FLOAT16_4;
3205 } else
3206 pCaps->DeclTypes = 0;
3208 return WINED3D_OK;
3211 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
3212 and fields being inserted in the middle, a new structure is used in place */
3213 static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, HWND hFocusWindow,
3214 DWORD BehaviourFlags, IWineD3DDevice** ppReturnedDeviceInterface,
3215 IUnknown *parent) {
3217 IWineD3DDeviceImpl *object = NULL;
3218 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3219 WINED3DDISPLAYMODE mode;
3220 int i;
3222 /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
3223 * number and create a device without a 3D adapter for 2D only operation.
3225 if (IWineD3D_GetAdapterCount(iface) && Adapter >= IWineD3D_GetAdapterCount(iface)) {
3226 return WINED3DERR_INVALIDCALL;
3229 /* Create a WineD3DDevice object */
3230 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
3231 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
3232 TRACE("Created WineD3DDevice object @ %p\n", object);
3233 if (NULL == object) {
3234 return WINED3DERR_OUTOFVIDEOMEMORY;
3237 /* Set up initial COM information */
3238 object->lpVtbl = &IWineD3DDevice_Vtbl;
3239 object->ref = 1;
3240 object->wineD3D = iface;
3241 object->adapter = numAdapters ? &Adapters[Adapter] : NULL;
3242 IWineD3D_AddRef(object->wineD3D);
3243 object->parent = parent;
3244 list_init(&object->resources);
3245 list_init(&object->shaders);
3247 if(This->dxVersion == 7) {
3248 object->surface_alignment = 8;
3249 } else {
3250 object->surface_alignment = 4;
3252 object->posFixup[0] = 1.0; /* This is needed to get the x coord unmodified through a MAD */
3254 /* Set the state up as invalid until the device is fully created */
3255 object->state = WINED3DERR_DRIVERINTERNALERROR;
3257 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %x, RetDevInt: %p)\n", This, Adapter, DeviceType,
3258 hFocusWindow, BehaviourFlags, ppReturnedDeviceInterface);
3260 /* Save the creation parameters */
3261 object->createParms.AdapterOrdinal = Adapter;
3262 object->createParms.DeviceType = DeviceType;
3263 object->createParms.hFocusWindow = hFocusWindow;
3264 object->createParms.BehaviorFlags = BehaviourFlags;
3266 /* Initialize other useful values */
3267 object->adapterNo = Adapter;
3268 object->devType = DeviceType;
3270 select_shader_mode(&GLINFO_LOCATION, DeviceType, &object->ps_selected_mode, &object->vs_selected_mode);
3271 object->shader_backend = select_shader_backend(Adapter, DeviceType);
3273 /* Prefer the vtable with functions optimized for single dirtifyable objects if the shader
3274 * model can deal with that. It is essentially the same, just with adjusted
3275 * Set*ShaderConstantF implementations
3277 if(object->shader_backend->shader_dirtifyable_constants((IWineD3DDevice *) object)) {
3278 object->lpVtbl = &IWineD3DDevice_DirtyConst_Vtbl;
3281 /* set the state of the device to valid */
3282 object->state = WINED3D_OK;
3284 /* Get the initial screen setup for ddraw */
3285 IWineD3DImpl_GetAdapterDisplayMode(iface, Adapter, &mode);
3287 object->ddraw_width = mode.Width;
3288 object->ddraw_height = mode.Height;
3289 object->ddraw_format = mode.Format;
3291 for(i = 0; i < PATCHMAP_SIZE; i++) {
3292 list_init(&object->patches[i]);
3294 return WINED3D_OK;
3296 #undef GLINFO_LOCATION
3298 static HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
3299 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3300 IUnknown_AddRef(This->parent);
3301 *pParent = This->parent;
3302 return WINED3D_OK;
3305 ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface) {
3306 IUnknown* surfaceParent;
3307 TRACE("(%p) call back\n", pSurface);
3309 /* Now, release the parent, which will take care of cleaning up the surface for us */
3310 IWineD3DSurface_GetParent(pSurface, &surfaceParent);
3311 IUnknown_Release(surfaceParent);
3312 return IUnknown_Release(surfaceParent);
3315 ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pVolume) {
3316 IUnknown* volumeParent;
3317 TRACE("(%p) call back\n", pVolume);
3319 /* Now, release the parent, which will take care of cleaning up the volume for us */
3320 IWineD3DVolume_GetParent(pVolume, &volumeParent);
3321 IUnknown_Release(volumeParent);
3322 return IUnknown_Release(volumeParent);
3325 static BOOL implementation_is_apple(WineD3D_GL_Info *gl_info) {
3326 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
3327 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
3328 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
3330 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
3331 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
3332 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
3333 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
3334 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
3335 * the chance that other implementations support them is rather small since Win32 QuickTime uses
3336 * DirectDraw, not OpenGL.
3338 if(gl_info->supported[APPLE_FENCE] &&
3339 gl_info->supported[APPLE_CLIENT_STORAGE] &&
3340 gl_info->supported[APPLE_FLUSH_RENDER] &&
3341 gl_info->supported[APPLE_YCBCR_422]) {
3342 TRACE_(d3d_caps)("GL_APPLE_fence, GL_APPLE_client_storage, GL_APPLE_flush_render and GL_ycbcr_422 are supported\n");
3343 TRACE_(d3d_caps)("Activating MacOS fixups\n");
3344 return TRUE;
3345 } else {
3346 TRACE_(d3d_caps)("Apple extensions are not supported\n");
3347 TRACE_(d3d_caps)("Not activating MacOS fixups\n");
3348 return FALSE;
3352 #define GLINFO_LOCATION (*gl_info)
3353 static void test_pbo_functionality(WineD3D_GL_Info *gl_info) {
3354 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
3355 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
3356 * all the texture. This function detects this bug by its symptom and disables PBOs
3357 * if the test fails.
3359 * The test uplaods a 4x4 texture via the PBO in the "native" format GL_BGRA,
3360 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
3361 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
3362 * read back is compared to the original. If they are equal PBOs are assumed to work,
3363 * otherwise the PBO extension is disabled.
3365 GLuint texture, pbo;
3366 static const unsigned int pattern[] = {
3367 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
3368 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
3369 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
3370 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
3372 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
3374 if(!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) {
3375 /* No PBO -> No point in testing them */
3376 return;
3379 while(glGetError());
3380 glGenTextures(1, &texture);
3381 glBindTexture(GL_TEXTURE_2D, texture);
3382 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
3383 checkGLcall("Specifying the PBO test texture\n");
3385 GL_EXTCALL(glGenBuffersARB(1, &pbo));
3386 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
3387 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
3388 checkGLcall("Specifying the PBO test pbo\n");
3390 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
3391 checkGLcall("Loading the PBO test texture\n");
3393 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
3394 glFinish(); /* just to be sure */
3396 memset(check, 0, sizeof(check));
3397 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
3398 checkGLcall("Reading back the PBO test texture\n");
3400 glDeleteTextures(1, &texture);
3401 GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
3402 checkGLcall("PBO test cleanup\n");
3404 if(memcmp(check, pattern, sizeof(check)) != 0) {
3405 WARN_(d3d_caps)("PBO test failed, read back data doesn't match original\n");
3406 WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance\n");
3407 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
3408 } else {
3409 TRACE_(d3d_caps)("PBO test successful\n");
3412 #undef GLINFO_LOCATION
3414 /* Certain applications(Steam) complain if we report an outdated driver version. In general,
3415 * reporting a driver version is moot because we are not the Windows driver, and we have different
3416 * bugs, features, etc.
3418 * If a card is not found in this table, the gl driver version is reported
3420 struct driver_version_information {
3421 WORD vendor; /* reported PCI card vendor ID */
3422 WORD card; /* reported PCI card device ID */
3423 WORD hipart_hi, hipart_lo; /* driver hiword to report */
3424 WORD lopart_hi, lopart_lo; /* driver loword to report */
3427 static const struct driver_version_information driver_version_table[] = {
3428 /* Nvidia drivers. Geforce FX and newer cards are supported by the current driver */
3429 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, 7, 15, 10, 16921 },
3430 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, 7, 15, 10, 16921 },
3431 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, 7, 15, 10, 16921 },
3432 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, 7, 15, 10, 16921 },
3433 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, 7, 15, 10, 16921 },
3434 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, 7, 15, 10, 16921 },
3435 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, 7, 15, 10, 16921 },
3436 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, 7, 15, 10, 16921 },
3437 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, 7, 15, 10, 16921 },
3438 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, 7, 15, 10, 16921 },
3439 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, 7, 15, 10, 16921 },
3440 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, 7, 15, 10, 16921 },
3441 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, 7, 15, 10, 16921 },
3442 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, 7, 15, 10, 16921 },
3444 /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode */
3445 {VENDOR_ATI, CARD_ATI_RADEON_9500, 6, 14, 10, 6764 },
3446 {VENDOR_ATI, CARD_ATI_RADEON_X700, 6, 14, 10, 6764 },
3447 {VENDOR_ATI, CARD_ATI_RADEON_X1600, 6, 14, 10, 6764 },
3448 {VENDOR_ATI, CARD_ATI_RADEON_HD2300, 6, 14, 10, 6764 },
3449 {VENDOR_ATI, CARD_ATI_RADEON_HD2600, 6, 14, 10, 6764 },
3450 {VENDOR_ATI, CARD_ATI_RADEON_HD2900, 6, 14, 10, 6764 },
3452 /* TODO: Add information about legacy nvidia and ATI hardware, Intel and other cards */
3455 static void fixup_extensions(WineD3D_GL_Info *gl_info) {
3456 unsigned int i;
3457 BOOL apple = implementation_is_apple(gl_info);
3459 if(apple) {
3460 /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
3461 * used it falls back to software. While the compiler can detect if the shader uses all declared
3462 * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
3463 * using relative addressing falls back to software.
3465 * ARB vp gives the correct amount of uniforms, so use it instead of GLSL
3467 if(gl_info->vs_glsl_constantsF <= gl_info->vs_arb_constantsF) {
3468 FIXME("GLSL doesn't advertise more vertex shader uniforms than ARB. Driver fixup outdated?\n");
3469 } else {
3470 TRACE("Driver claims %u GLSL vs uniforms, replacing with %u ARB vp uniforms\n",
3471 gl_info->vs_glsl_constantsF, gl_info->vs_arb_constantsF);
3472 gl_info->vs_glsl_constantsF = gl_info->vs_arb_constantsF;
3475 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
3476 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
3477 * If real NP2 textures are used, the driver falls back to software. So remove the supported
3478 * flag for this extension
3480 if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] && gl_info->gl_vendor == VENDOR_ATI) {
3481 if(gl_info->gl_card == CARD_ATI_RADEON_X700 || gl_info->gl_card == CARD_ATI_RADEON_X1600 ||
3482 gl_info->gl_card == CARD_ATI_RADEON_9500 || gl_info->gl_card == CARD_ATI_RADEON_8500 ||
3483 gl_info->gl_card == CARD_ATI_RADEON_7200 || gl_info->gl_card == CARD_ATI_RAGE_128PRO) {
3484 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing\n");
3485 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
3486 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
3490 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
3491 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
3492 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
3493 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
3494 * according to the spec.
3496 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
3497 * makes the shader slower and eats instruction slots which should be available to the d3d app.
3499 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
3500 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
3501 * this workaround is activated on cards that do not need it, it won't break things, just affect
3502 * performance negatively.
3504 if(gl_info->gl_vendor == VENDOR_INTEL ||
3505 (gl_info->gl_vendor == VENDOR_ATI && gl_info->gl_card != CARD_ATI_RADEON_X1600)) {
3506 TRACE("Enabling vertex texture coord fixes in vertex shaders\n");
3507 gl_info->set_texcoord_w = TRUE;
3511 /* Find out if PBOs work as they are supposed to */
3512 test_pbo_functionality(gl_info);
3514 /* Fixup the driver version */
3515 for(i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++) {
3516 if(gl_info->gl_vendor == driver_version_table[i].vendor &&
3517 gl_info->gl_card == driver_version_table[i].card) {
3518 TRACE_(d3d_caps)("Found card 0x%04x, 0x%04x in driver version DB\n", gl_info->gl_vendor, gl_info->gl_card);
3520 gl_info->driver_version = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
3521 driver_version_table[i].lopart_lo);
3522 gl_info->driver_version_hipart = MAKEDWORD_VERSION(driver_version_table[i].hipart_hi,
3523 driver_version_table[i].hipart_lo);
3524 break;
3529 void invalid_func(void *data) {
3530 ERR("Invalid vertex attribute function called\n");
3531 DebugBreak();
3534 #define GLINFO_LOCATION (Adapters[0].gl_info)
3536 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
3537 * the extension detection and are used in drawStridedSlow
3539 static void position_d3dcolor(void *data) {
3540 DWORD pos = *((DWORD *) data);
3542 FIXME("Add a test for fixed function position from d3dcolor type\n");
3543 glVertex4s(D3DCOLOR_B_R(pos),
3544 D3DCOLOR_B_G(pos),
3545 D3DCOLOR_B_B(pos),
3546 D3DCOLOR_B_A(pos));
3548 static void position_float4(void *data) {
3549 GLfloat *pos = (float *) data;
3551 if (pos[3] < eps && pos[3] > -eps)
3552 glVertex3fv(pos);
3553 else {
3554 float w = 1.0 / pos[3];
3556 glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
3560 static void diffuse_d3dcolor(void *data) {
3561 DWORD diffuseColor = *((DWORD *) data);
3563 glColor4ub(D3DCOLOR_B_R(diffuseColor),
3564 D3DCOLOR_B_G(diffuseColor),
3565 D3DCOLOR_B_B(diffuseColor),
3566 D3DCOLOR_B_A(diffuseColor));
3569 static void specular_d3dcolor(void *data) {
3570 DWORD specularColor = *((DWORD *) data);
3572 GL_EXTCALL(glSecondaryColor3ubEXT)(D3DCOLOR_B_R(specularColor),
3573 D3DCOLOR_B_G(specularColor),
3574 D3DCOLOR_B_B(specularColor));
3576 static void warn_no_specular_func(void *data) {
3577 WARN("GL_EXT_secondary_color not supported\n");
3580 void fillGLAttribFuncs(WineD3D_GL_Info *gl_info) {
3581 position_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3582 position_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3583 position_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glVertex3fv;
3584 position_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) position_float4;
3585 position_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) position_d3dcolor;
3586 position_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3587 position_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3588 position_funcs[WINED3DDECLTYPE_SHORT4] = (void *) glVertex2sv;
3589 position_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3590 position_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3591 position_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3592 position_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3593 position_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3594 position_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3595 position_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3596 position_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3597 position_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3599 diffuse_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3600 diffuse_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3601 diffuse_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glColor3fv;
3602 diffuse_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) glColor4fv;
3603 diffuse_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) diffuse_d3dcolor;
3604 diffuse_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3605 diffuse_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3606 diffuse_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3607 diffuse_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) glColor4ubv;
3608 diffuse_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3609 diffuse_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) glColor4sv;
3610 diffuse_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3611 diffuse_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) glColor4usv;
3612 diffuse_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3613 diffuse_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3614 diffuse_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3615 diffuse_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3617 /* No 4 component entry points here */
3618 specular_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3619 specular_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3620 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
3621 specular_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) GL_EXTCALL(glSecondaryColor3fvEXT);
3622 } else {
3623 specular_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) warn_no_specular_func;
3625 specular_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) invalid_func;
3626 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
3627 specular_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) specular_d3dcolor;
3628 } else {
3629 specular_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) warn_no_specular_func;
3631 specular_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3632 specular_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3633 specular_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3634 specular_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3635 specular_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3636 specular_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3637 specular_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3638 specular_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3639 specular_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3640 specular_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3641 specular_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3642 specular_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3644 /* Only 3 component entry points here. Test how others behave. Float4 normals are used
3645 * by one of our tests, trying to pass it to the pixel shader, which fails on Windows.
3647 normal_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3648 normal_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3649 normal_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glNormal3fv;
3650 normal_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) glNormal3fv; /* Just ignore the 4th value */
3651 normal_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) invalid_func;
3652 normal_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3653 normal_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3654 normal_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3655 normal_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3656 normal_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3657 normal_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3658 normal_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3659 normal_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3660 normal_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3661 normal_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3662 normal_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3663 normal_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3666 #define PUSH1(att) attribs[nAttribs++] = (att);
3667 BOOL InitAdapters(void) {
3668 static HMODULE mod_gl;
3669 BOOL ret;
3670 int ps_selected_mode, vs_selected_mode;
3672 /* No need to hold any lock. The calling library makes sure only one thread calls
3673 * wined3d simultaneously
3675 if(numAdapters > 0) return Adapters[0].opengl;
3677 TRACE("Initializing adapters\n");
3679 if(!mod_gl) {
3680 #ifdef USE_WIN32_OPENGL
3681 #define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
3682 mod_gl = LoadLibraryA("opengl32.dll");
3683 if(!mod_gl) {
3684 ERR("Can't load opengl32.dll!\n");
3685 goto nogl_adapter;
3687 #else
3688 #define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
3689 /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
3690 mod_gl = GetModuleHandleA("gdi32.dll");
3691 #endif
3694 /* Load WGL core functions from opengl32.dll */
3695 #define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn);
3696 WGL_FUNCS_GEN;
3697 #undef USE_WGL_FUNC
3699 if(!pwglGetProcAddress) {
3700 ERR("Unable to load wglGetProcAddress!\n");
3701 goto nogl_adapter;
3704 /* Dynamically load all GL core functions */
3705 GL_FUNCS_GEN;
3706 #undef USE_GL_FUNC
3708 /* For now only one default adapter */
3710 int iPixelFormat;
3711 int attribs[8];
3712 int values[8];
3713 int nAttribs = 0;
3714 int res;
3715 WineD3D_PixelFormat *cfgs;
3716 int attribute;
3717 DISPLAY_DEVICEW DisplayDevice;
3718 HDC hdc;
3720 TRACE("Initializing default adapter\n");
3721 Adapters[0].num = 0;
3722 Adapters[0].monitorPoint.x = -1;
3723 Adapters[0].monitorPoint.y = -1;
3725 if (!WineD3D_CreateFakeGLContext()) {
3726 ERR("Failed to get a gl context for default adapter\n");
3727 WineD3D_ReleaseFakeGLContext();
3728 goto nogl_adapter;
3731 ret = IWineD3DImpl_FillGLCaps(&Adapters[0].gl_info);
3732 if(!ret) {
3733 ERR("Failed to initialize gl caps for default adapter\n");
3734 WineD3D_ReleaseFakeGLContext();
3735 goto nogl_adapter;
3737 ret = initPixelFormats(&Adapters[0].gl_info);
3738 if(!ret) {
3739 ERR("Failed to init gl formats\n");
3740 WineD3D_ReleaseFakeGLContext();
3741 goto nogl_adapter;
3744 hdc = pwglGetCurrentDC();
3745 if(!hdc) {
3746 ERR("Failed to get gl HDC\n");
3747 WineD3D_ReleaseFakeGLContext();
3748 goto nogl_adapter;
3751 Adapters[0].driver = "Display";
3752 Adapters[0].description = "Direct3D HAL";
3754 /* Use the VideoRamSize registry setting when set */
3755 if(wined3d_settings.emulated_textureram)
3756 Adapters[0].TextureRam = wined3d_settings.emulated_textureram;
3757 else
3758 Adapters[0].TextureRam = Adapters[0].gl_info.vidmem;
3759 Adapters[0].UsedTextureRam = 0;
3760 TRACE("Emulating %dMB of texture ram\n", Adapters[0].TextureRam/(1024*1024));
3762 /* Initialize the Adapter's DeviceName which is required for ChangeDisplaySettings and friends */
3763 DisplayDevice.cb = sizeof(DisplayDevice);
3764 EnumDisplayDevicesW(NULL, 0 /* Adapter 0 = iDevNum 0 */, &DisplayDevice, 0);
3765 TRACE("DeviceName: %s\n", debugstr_w(DisplayDevice.DeviceName));
3766 strcpyW(Adapters[0].DeviceName, DisplayDevice.DeviceName);
3768 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
3769 GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, &attribute, &Adapters[0].nCfgs));
3771 Adapters[0].cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Adapters[0].nCfgs *sizeof(WineD3D_PixelFormat));
3772 cfgs = Adapters[0].cfgs;
3773 PUSH1(WGL_RED_BITS_ARB)
3774 PUSH1(WGL_GREEN_BITS_ARB)
3775 PUSH1(WGL_BLUE_BITS_ARB)
3776 PUSH1(WGL_ALPHA_BITS_ARB)
3777 PUSH1(WGL_DEPTH_BITS_ARB)
3778 PUSH1(WGL_STENCIL_BITS_ARB)
3779 PUSH1(WGL_DRAW_TO_WINDOW_ARB)
3780 PUSH1(WGL_PIXEL_TYPE_ARB)
3782 for(iPixelFormat=1; iPixelFormat<=Adapters[0].nCfgs; iPixelFormat++) {
3783 res = GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, nAttribs, attribs, values));
3785 if(!res)
3786 continue;
3788 /* Cache the pixel format */
3789 cfgs->iPixelFormat = iPixelFormat;
3790 cfgs->redSize = values[0];
3791 cfgs->greenSize = values[1];
3792 cfgs->blueSize = values[2];
3793 cfgs->alphaSize = values[3];
3794 cfgs->depthSize = values[4];
3795 cfgs->stencilSize = values[5];
3796 cfgs->windowDrawable = values[6];
3797 cfgs->iPixelType = values[7];
3799 cfgs->pbufferDrawable = FALSE;
3800 /* Check for pbuffer support when it is around as wglGetPixelFormatAttribiv fails for unknown
3801 attributes. */
3802 if(GL_SUPPORT(WGL_ARB_PBUFFER)) {
3803 int attrib = WGL_DRAW_TO_PBUFFER_ARB;
3804 int value;
3805 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 1, &attrib, &value)))
3806 cfgs->pbufferDrawable = value;
3809 TRACE("iPixelFormat=%d, iPixelType=%#x, RGBA=%d/%d/%d/%d, depth=%d, stencil=%d, windowDrawable=%d, pbufferDrawable=%d\n", cfgs->iPixelFormat, cfgs->iPixelType, cfgs->redSize, cfgs->greenSize, cfgs->blueSize, cfgs->alphaSize, cfgs->depthSize, cfgs->stencilSize, cfgs->windowDrawable, cfgs->pbufferDrawable);
3810 cfgs++;
3813 fixup_extensions(&Adapters[0].gl_info);
3815 WineD3D_ReleaseFakeGLContext();
3817 select_shader_mode(&Adapters[0].gl_info, WINED3DDEVTYPE_HAL, &ps_selected_mode, &vs_selected_mode);
3818 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &Adapters[0].gl_info);
3819 fillGLAttribFuncs(&Adapters[0].gl_info);
3820 init_type_lookup(&Adapters[0].gl_info);
3821 Adapters[0].opengl = TRUE;
3823 numAdapters = 1;
3824 TRACE("%d adapters successfully initialized\n", numAdapters);
3826 return TRUE;
3828 nogl_adapter:
3829 /* Initialize an adapter for ddraw-only memory counting */
3830 memset(Adapters, 0, sizeof(Adapters));
3831 Adapters[0].num = 0;
3832 Adapters[0].opengl = FALSE;
3833 Adapters[0].monitorPoint.x = -1;
3834 Adapters[0].monitorPoint.y = -1;
3836 Adapters[0].driver = "Display";
3837 Adapters[0].description = "WineD3D DirectDraw Emulation";
3838 if(wined3d_settings.emulated_textureram) {
3839 Adapters[0].TextureRam = wined3d_settings.emulated_textureram;
3840 } else {
3841 Adapters[0].TextureRam = 8 * 1024 * 1024; /* This is plenty for a DDraw-only card */
3844 numAdapters = 1;
3845 return FALSE;
3847 #undef PUSH1
3848 #undef GLINFO_LOCATION
3850 /**********************************************************
3851 * IWineD3D VTbl follows
3852 **********************************************************/
3854 const IWineD3DVtbl IWineD3D_Vtbl =
3856 /* IUnknown */
3857 IWineD3DImpl_QueryInterface,
3858 IWineD3DImpl_AddRef,
3859 IWineD3DImpl_Release,
3860 /* IWineD3D */
3861 IWineD3DImpl_GetParent,
3862 IWineD3DImpl_GetAdapterCount,
3863 IWineD3DImpl_RegisterSoftwareDevice,
3864 IWineD3DImpl_GetAdapterMonitor,
3865 IWineD3DImpl_GetAdapterModeCount,
3866 IWineD3DImpl_EnumAdapterModes,
3867 IWineD3DImpl_GetAdapterDisplayMode,
3868 IWineD3DImpl_GetAdapterIdentifier,
3869 IWineD3DImpl_CheckDeviceMultiSampleType,
3870 IWineD3DImpl_CheckDepthStencilMatch,
3871 IWineD3DImpl_CheckDeviceType,
3872 IWineD3DImpl_CheckDeviceFormat,
3873 IWineD3DImpl_CheckDeviceFormatConversion,
3874 IWineD3DImpl_GetDeviceCaps,
3875 IWineD3DImpl_CreateDevice