wined3d: Add D3DUSAGE_QUERY_PIXELSHADER_BLENDING to CheckDeviceFormat.
[wine/multimedia.git] / dlls / wined3d / directx.c
blobc8e93255d3827212333989a96171871096999c53
1 /*
2 * IWineD3D implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 /* Compile time diagnostics: */
26 #ifndef DEBUG_SINGLE_MODE
27 /* Set to 1 to force only a single display mode to be exposed: */
28 #define DEBUG_SINGLE_MODE 0
29 #endif
32 #include "config.h"
33 #include <assert.h>
34 #include "wined3d_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
37 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
39 /* The d3d device ID */
40 static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
42 /* Extension detection */
43 static const struct {
44 const char *extension_string;
45 GL_SupportedExt extension;
46 DWORD version;
47 } EXTENSION_MAP[] = {
48 /* APPLE */
49 {"GL_APPLE_client_storage", APPLE_CLIENT_STORAGE, 0 },
50 {"GL_APPLE_fence", APPLE_FENCE, 0 },
51 {"GL_APPLE_flush_render", APPLE_FLUSH_RENDER, 0 },
52 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422, 0 },
53 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS, 0 },
55 /* ATI */
56 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL, 0 },
57 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3, 0 },
58 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE, 0 },
59 {"GL_ATI_envmap_bumpmap", ATI_ENVMAP_BUMPMAP, 0 },
60 {"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER, 0 },
62 /* ARB */
63 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS, 0 },
64 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM, 0 },
65 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER, 0 },
66 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL, 0 },
67 {"GL_ARB_imaging", ARB_IMAGING, 0 },
68 {"GL_ARB_multisample", ARB_MULTISAMPLE, 0 }, /* needs GLX_ARB_MULTISAMPLE as well */
69 {"GL_ARB_multitexture", ARB_MULTITEXTURE, 0 },
70 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY, 0 },
71 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT, 0 },
72 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS, 0 },
73 {"GL_ARB_point_sprite", ARB_POINT_SPRITE, 0 },
74 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP, 0 },
75 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION, 0 },
76 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP, 0 },
77 {"GL_ARB_texture_env_add", ARB_TEXTURE_ENV_ADD, 0 },
78 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE, 0 },
79 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3, 0 },
80 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT, 0 },
81 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT, 0 },
82 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO, 0 },
83 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE, 0 },
84 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND, 0 },
85 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT, 0 },
86 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM, 0 },
87 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER, 0 },
88 {"GL_ARB_shader_objects", ARB_SHADER_OBJECTS, 0 },
90 /* EXT */
91 {"GL_EXT_blend_color", EXT_BLEND_COLOR, 0 },
92 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX, 0 },
93 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE, 0 },
94 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE, 0 },
95 {"GL_EXT_fog_coord", EXT_FOG_COORD, 0 },
96 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT, 0 },
97 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT, 0 },
98 {"GL_EXT_paletted_texture", EXT_PALETTED_TEXTURE, 0 },
99 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS, 0 },
100 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR, 0 },
101 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE, 0 },
102 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP, 0 },
103 {"GL_EXT_texture3D", EXT_TEXTURE3D, MAKEDWORD_VERSION(1, 2) },
104 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC, 0 },
105 {"GL_EXT_texture_env_add", EXT_TEXTURE_ENV_ADD, 0 },
106 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE, 0 },
107 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3, 0 },
108 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB, 0 },
109 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC, 0 },
110 {"GL_EXT_texture_lod", EXT_TEXTURE_LOD, 0 },
111 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS, 0 },
112 {"GL_EXT_vertex_shader", EXT_VERTEX_SHADER, 0 },
113 {"GL_EXT_vertex_weighting", EXT_VERTEX_WEIGHTING, 0 },
114 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS, 0 },
116 /* NV */
117 {"GL_NV_half_float", NV_HALF_FLOAT, 0 },
118 {"GL_NV_fence", NV_FENCE, 0 },
119 {"GL_NV_fog_distance", NV_FOG_DISTANCE, 0 },
120 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM, 0 },
121 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2, 0 },
122 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS, 0 },
123 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2, 0 },
124 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION, 0 },
125 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4, 0 },
126 {"GL_NV_texture_shader", NV_TEXTURE_SHADER, 0 },
127 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2, 0 },
128 {"GL_NV_texture_shader3", NV_TEXTURE_SHADER3, 0 },
129 {"GL_NV_occlusion_query", NV_OCCLUSION_QUERY, 0 },
130 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM, 0 },
131 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1, 0 },
132 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2, 0 },
133 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3, 0 },
134 {"GL_NV_depth_clamp", NV_DEPTH_CLAMP, 0 },
135 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT, 0 },
137 /* SGI */
138 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP, 0 },
141 /**********************************************************
142 * Utility functions follow
143 **********************************************************/
145 /* Adapters */
146 static int numAdapters = 0;
147 static struct WineD3DAdapter Adapters[1];
149 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat);
151 /* lookup tables */
152 int minLookup[MAX_LOOKUPS];
153 int maxLookup[MAX_LOOKUPS];
154 DWORD *stateLookup[MAX_LOOKUPS];
156 DWORD minMipLookup[WINED3DTEXF_ANISOTROPIC + 1][WINED3DTEXF_LINEAR + 1];
158 /* drawStridedSlow attributes */
159 glAttribFunc position_funcs[WINED3DDECLTYPE_UNUSED];
160 glAttribFunc diffuse_funcs[WINED3DDECLTYPE_UNUSED];
161 glAttribFunc specular_funcs[WINED3DDECLTYPE_UNUSED];
162 glAttribFunc normal_funcs[WINED3DDECLTYPE_UNUSED];
163 glTexAttribFunc texcoord_funcs[WINED3DDECLTYPE_UNUSED];
166 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created
167 * ie there is no GL Context - Get a default rendering context to enable the
168 * function query some info from GL
171 static int wined3d_fake_gl_context_ref = 0;
172 static BOOL wined3d_fake_gl_context_foreign;
173 static BOOL wined3d_fake_gl_context_available = FALSE;
174 static HDC wined3d_fake_gl_context_hdc = NULL;
175 static HWND wined3d_fake_gl_context_hwnd = NULL;
177 static CRITICAL_SECTION wined3d_fake_gl_context_cs;
178 static CRITICAL_SECTION_DEBUG wined3d_fake_gl_context_cs_debug =
180 0, 0, &wined3d_fake_gl_context_cs,
181 { &wined3d_fake_gl_context_cs_debug.ProcessLocksList,
182 &wined3d_fake_gl_context_cs_debug.ProcessLocksList },
183 0, 0, { (DWORD_PTR)(__FILE__ ": wined3d_fake_gl_context_cs") }
185 static CRITICAL_SECTION wined3d_fake_gl_context_cs = { &wined3d_fake_gl_context_cs_debug, -1, 0, 0, 0, 0 };
187 static void WineD3D_ReleaseFakeGLContext(void) {
188 HGLRC glCtx;
190 EnterCriticalSection(&wined3d_fake_gl_context_cs);
192 if(!wined3d_fake_gl_context_available) {
193 TRACE_(d3d_caps)("context not available\n");
194 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
195 return;
198 glCtx = pwglGetCurrentContext();
200 TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref);
201 if (0 == (--wined3d_fake_gl_context_ref) ) {
202 if(!wined3d_fake_gl_context_foreign && glCtx) {
203 TRACE_(d3d_caps)("destroying fake GL context\n");
204 pwglMakeCurrent(NULL, NULL);
205 pwglDeleteContext(glCtx);
207 if(wined3d_fake_gl_context_hdc)
208 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
209 wined3d_fake_gl_context_hdc = NULL; /* Make sure we don't think that it is still around */
210 if(wined3d_fake_gl_context_hwnd)
211 DestroyWindow(wined3d_fake_gl_context_hwnd);
212 wined3d_fake_gl_context_hwnd = NULL;
213 wined3d_fake_gl_context_available = FALSE;
215 assert(wined3d_fake_gl_context_ref >= 0);
217 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
220 static BOOL WineD3D_CreateFakeGLContext(void) {
221 HGLRC glCtx = NULL;
223 EnterCriticalSection(&wined3d_fake_gl_context_cs);
225 TRACE("getting context...\n");
226 if(wined3d_fake_gl_context_ref > 0) goto ret;
227 assert(0 == wined3d_fake_gl_context_ref);
229 wined3d_fake_gl_context_foreign = TRUE;
231 glCtx = pwglGetCurrentContext();
232 if (!glCtx) {
233 PIXELFORMATDESCRIPTOR pfd;
234 int iPixelFormat;
236 wined3d_fake_gl_context_foreign = FALSE;
238 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes */
239 wined3d_fake_gl_context_hwnd = CreateWindowA("WineD3D_OpenGL", "WineD3D fake window", WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
240 if(!wined3d_fake_gl_context_hwnd) {
241 ERR("HWND creation failed!\n");
242 goto fail;
244 wined3d_fake_gl_context_hdc = GetDC(wined3d_fake_gl_context_hwnd);
245 if(!wined3d_fake_gl_context_hdc) {
246 ERR("GetDC failed!\n");
247 goto fail;
250 /* PixelFormat selection */
251 ZeroMemory(&pfd, sizeof(pfd));
252 pfd.nSize = sizeof(pfd);
253 pfd.nVersion = 1;
254 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;/*PFD_GENERIC_ACCELERATED*/
255 pfd.iPixelType = PFD_TYPE_RGBA;
256 pfd.cColorBits = 32;
257 pfd.iLayerType = PFD_MAIN_PLANE;
259 iPixelFormat = ChoosePixelFormat(wined3d_fake_gl_context_hdc, &pfd);
260 if(!iPixelFormat) {
261 /* If this happens something is very wrong as ChoosePixelFormat barely fails */
262 ERR("Can't find a suitable iPixelFormat\n");
263 goto fail;
265 DescribePixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, sizeof(pfd), &pfd);
266 SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd);
268 /* Create a GL context */
269 glCtx = pwglCreateContext(wined3d_fake_gl_context_hdc);
270 if (!glCtx) {
271 WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
272 goto fail;
275 /* Make it the current GL context */
276 if (!pwglMakeCurrent(wined3d_fake_gl_context_hdc, glCtx)) {
277 WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
278 goto fail;
282 ret:
283 TRACE("incrementing ref from %i\n", wined3d_fake_gl_context_ref);
284 wined3d_fake_gl_context_ref++;
285 wined3d_fake_gl_context_available = TRUE;
286 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
287 return TRUE;
288 fail:
289 if(wined3d_fake_gl_context_hdc)
290 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
291 wined3d_fake_gl_context_hdc = NULL;
292 if(wined3d_fake_gl_context_hwnd)
293 DestroyWindow(wined3d_fake_gl_context_hwnd);
294 wined3d_fake_gl_context_hwnd = NULL;
295 if(glCtx) pwglDeleteContext(glCtx);
296 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
297 return FALSE;
300 /* Adjust the amount of used texture memory */
301 long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram){
302 UINT Adapter = D3DDevice->adapterNo;
304 Adapters[Adapter].UsedTextureRam += glram;
305 TRACE("Adjusted gl ram by %ld to %d\n", glram, Adapters[Adapter].UsedTextureRam);
306 return Adapters[Adapter].UsedTextureRam;
309 /**********************************************************
310 * IUnknown parts follows
311 **********************************************************/
313 static HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
315 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
317 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
318 if (IsEqualGUID(riid, &IID_IUnknown)
319 || IsEqualGUID(riid, &IID_IWineD3DBase)
320 || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
321 IUnknown_AddRef(iface);
322 *ppobj = This;
323 return S_OK;
325 *ppobj = NULL;
326 return E_NOINTERFACE;
329 static ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
330 IWineD3DImpl *This = (IWineD3DImpl *)iface;
331 ULONG refCount = InterlockedIncrement(&This->ref);
333 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
334 return refCount;
337 static ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
338 IWineD3DImpl *This = (IWineD3DImpl *)iface;
339 ULONG ref;
340 TRACE("(%p) : Releasing from %d\n", This, This->ref);
341 ref = InterlockedDecrement(&This->ref);
342 if (ref == 0) {
343 HeapFree(GetProcessHeap(), 0, This);
346 return ref;
349 /* Set the shader type for this device, depending on the given capabilities,
350 * the device type, and the user preferences in wined3d_settings */
352 void select_shader_mode(
353 WineD3D_GL_Info *gl_info,
354 WINED3DDEVTYPE DeviceType,
355 int* ps_selected,
356 int* vs_selected) {
358 if (wined3d_settings.vs_mode == VS_NONE) {
359 *vs_selected = SHADER_NONE;
360 } else if (gl_info->supported[ARB_VERTEX_SHADER] && wined3d_settings.glslRequested) {
361 /* Geforce4 cards support GLSL but for vertex shaders only. Further its reported GLSL caps are
362 * wrong. This combined with the fact that glsl won't offer more features or performance, use ARB
363 * shaders only on this card. */
364 if(gl_info->vs_nv_version && gl_info->vs_nv_version < VS_VERSION_20)
365 *vs_selected = SHADER_ARB;
366 else
367 *vs_selected = SHADER_GLSL;
368 } else if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
369 *vs_selected = SHADER_ARB;
370 } else {
371 *vs_selected = SHADER_NONE;
374 if (wined3d_settings.ps_mode == PS_NONE) {
375 *ps_selected = SHADER_NONE;
376 } else if (gl_info->supported[ARB_FRAGMENT_SHADER] && wined3d_settings.glslRequested) {
377 *ps_selected = SHADER_GLSL;
378 } else if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
379 *ps_selected = SHADER_ARB;
380 } else if (gl_info->supported[ATI_FRAGMENT_SHADER]) {
381 *ps_selected = SHADER_ATI;
382 } else {
383 *ps_selected = SHADER_NONE;
387 /** Select the number of report maximum shader constants based on the selected shader modes */
388 static void select_shader_max_constants(
389 int ps_selected_mode,
390 int vs_selected_mode,
391 WineD3D_GL_Info *gl_info) {
393 switch (vs_selected_mode) {
394 case SHADER_GLSL:
395 /* Subtract the other potential uniforms from the max available (bools, ints, and 1 row of projection matrix) */
396 gl_info->max_vshader_constantsF = gl_info->vs_glsl_constantsF - (MAX_CONST_B / 4) - MAX_CONST_I - 1;
397 break;
398 case SHADER_ARB:
399 /* We have to subtract any other PARAMs that we might use in our shader programs.
400 * ATI seems to count 2 implicit PARAMs when we use fog and NVIDIA counts 1,
401 * and we reference one row of the PROJECTION matrix which counts as 1 PARAM. */
402 gl_info->max_vshader_constantsF = gl_info->vs_arb_constantsF - 3;
403 break;
404 default:
405 gl_info->max_vshader_constantsF = 0;
406 break;
409 switch (ps_selected_mode) {
410 case SHADER_GLSL:
411 /* Subtract the other potential uniforms from the max available (bools & ints), and 2 states for fog.
412 * In theory the texbem instruction may need one more shader constant too. But lets assume
413 * that a sm <= 1.3 shader does not need all the uniforms provided by a glsl-capable card,
414 * and lets not take away a uniform needlessly from all other shaders.
416 gl_info->max_pshader_constantsF = gl_info->ps_glsl_constantsF - (MAX_CONST_B / 4) - MAX_CONST_I - 2;
417 break;
418 case SHADER_ARB:
419 /* The arb shader only loads the bump mapping environment matrix into the shader if it finds
420 * a free constant to do that, so only reduce the number of available constants by 2 for the fog states.
422 gl_info->max_pshader_constantsF = gl_info->ps_arb_constantsF - 2;
423 break;
424 default:
425 gl_info->max_pshader_constantsF = 0;
426 break;
430 /**********************************************************
431 * IWineD3D parts follows
432 **********************************************************/
434 #define GLINFO_LOCATION (*gl_info)
435 static inline BOOL test_arb_vs_offset_limit(WineD3D_GL_Info *gl_info) {
436 GLuint prog;
437 BOOL ret = FALSE;
438 const char *testcode =
439 "!!ARBvp1.0\n"
440 "PARAM C[66] = { program.env[0..65] };\n"
441 "ADDRESS A0;"
442 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
443 "ARL A0.x, zero.x;\n"
444 "MOV result.position, C[A0.x + 65];\n"
445 "END\n";
447 while(glGetError());
448 GL_EXTCALL(glGenProgramsARB(1, &prog));
449 if(!prog) {
450 ERR("Failed to create an ARB offset limit test program\n");
452 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
453 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
454 strlen(testcode), testcode));
455 if(glGetError() != 0) {
456 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
457 TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
458 ret = TRUE;
459 } else TRACE("OpenGL implementation allows offsets > 63\n");
461 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
462 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
463 checkGLcall("ARB vp offset limit test cleanup\n");
465 return ret;
468 static DWORD ver_for_ext(GL_SupportedExt ext)
470 unsigned int i;
471 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
472 if(EXTENSION_MAP[i].extension == ext) {
473 return EXTENSION_MAP[i].version;
476 return 0;
479 BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
480 const char *GL_Extensions = NULL;
481 const char *WGL_Extensions = NULL;
482 const char *gl_string = NULL;
483 const char *gl_string_cursor = NULL;
484 GLint gl_max;
485 GLfloat gl_floatv[2];
486 int major = 1, minor = 0;
487 BOOL return_value = TRUE;
488 unsigned i;
489 HDC hdc;
490 unsigned int vidmem=0;
492 TRACE_(d3d_caps)("(%p)\n", gl_info);
494 ENTER_GL();
496 gl_string = (const char *) glGetString(GL_RENDERER);
497 if (NULL == gl_string)
498 gl_string = "None";
499 strcpy(gl_info->gl_renderer, gl_string);
501 gl_string = (const char *) glGetString(GL_VENDOR);
502 TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
503 if (gl_string != NULL) {
504 /* Fill in the GL vendor */
505 if (strstr(gl_string, "NVIDIA")) {
506 gl_info->gl_vendor = VENDOR_NVIDIA;
507 } else if (strstr(gl_string, "ATI")) {
508 gl_info->gl_vendor = VENDOR_ATI;
509 } else if (strstr(gl_string, "Intel(R)") ||
510 strstr(gl_info->gl_renderer, "Intel(R)") ||
511 strstr(gl_string, "Intel Inc.")) {
512 gl_info->gl_vendor = VENDOR_INTEL;
513 } else if (strstr(gl_string, "Mesa")) {
514 gl_info->gl_vendor = VENDOR_MESA;
515 } else {
516 gl_info->gl_vendor = VENDOR_WINE;
518 } else {
519 gl_info->gl_vendor = VENDOR_WINE;
523 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
525 /* Parse the GL_VERSION field into major and minor information */
526 gl_string = (const char *) glGetString(GL_VERSION);
527 if (gl_string != NULL) {
529 /* First, parse the generic opengl version. This is supposed not to be convoluted with
530 * driver specific information
532 gl_string_cursor = gl_string;
533 major = atoi(gl_string_cursor);
534 if(major <= 0) {
535 ERR("Invalid opengl major version: %d\n", major);
537 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
538 ++gl_string_cursor;
540 if (*gl_string_cursor++ != '.') {
541 ERR_(d3d_caps)("Invalid opengl version string: %s\n", debugstr_a(gl_string));
543 minor = atoi(gl_string_cursor);
544 TRACE_(d3d_caps)("Found OpenGL version: %d.%d\n", major, minor);
545 gl_info->gl_version = MAKEDWORD_VERSION(major, minor);
547 /* Now parse the driver specific string which we'll report to the app */
548 switch (gl_info->gl_vendor) {
549 case VENDOR_NVIDIA:
550 gl_string_cursor = strstr(gl_string, "NVIDIA");
551 if (!gl_string_cursor) {
552 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
553 break;
556 gl_string_cursor = strstr(gl_string_cursor, " ");
557 if (!gl_string_cursor) {
558 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
559 break;
562 while (*gl_string_cursor == ' ') {
563 ++gl_string_cursor;
566 if (!*gl_string_cursor) {
567 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
568 break;
571 major = atoi(gl_string_cursor);
572 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
573 ++gl_string_cursor;
576 if (*gl_string_cursor++ != '.') {
577 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
578 break;
581 minor = atoi(gl_string_cursor);
582 minor = major*100+minor;
583 major = 10;
585 break;
587 case VENDOR_ATI:
588 major = minor = 0;
589 gl_string_cursor = strchr(gl_string, '-');
590 if (gl_string_cursor) {
591 int error = 0;
592 gl_string_cursor++;
594 /* Check if version number is of the form x.y.z */
595 if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
596 error = 1;
597 if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
598 error = 1;
599 if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
600 error = 1;
601 if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
602 error = 1;
604 /* Mark version number as malformed */
605 if (error)
606 gl_string_cursor = 0;
609 if (!gl_string_cursor)
610 WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
611 else {
612 major = *gl_string_cursor - '0';
613 minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
615 break;
617 case VENDOR_INTEL:
618 /* Apple and Mesa version strings look differently, but both provide intel drivers */
619 if(strstr(gl_string, "APPLE")) {
620 /* [0-9]+.[0-9]+ APPLE-[0-9]+.[0.9]+.[0.9]+
621 * We only need the first part, and use the APPLE as identification
622 * "1.2 APPLE-1.4.56"
624 gl_string_cursor = gl_string;
625 major = atoi(gl_string_cursor);
626 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
627 ++gl_string_cursor;
630 if (*gl_string_cursor++ != '.') {
631 ERR_(d3d_caps)("Invalid MacOS-Intel version string: %s\n", debugstr_a(gl_string));
632 break;
635 minor = atoi(gl_string_cursor);
636 break;
639 case VENDOR_MESA:
640 gl_string_cursor = strstr(gl_string, "Mesa");
641 gl_string_cursor = strstr(gl_string_cursor, " ");
642 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
643 if (*gl_string_cursor) {
644 char tmp[16];
645 int cursor = 0;
647 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
648 tmp[cursor++] = *gl_string_cursor;
649 ++gl_string_cursor;
651 tmp[cursor] = 0;
652 major = atoi(tmp);
654 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
655 ++gl_string_cursor;
657 cursor = 0;
658 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
659 tmp[cursor++] = *gl_string_cursor;
660 ++gl_string_cursor;
662 tmp[cursor] = 0;
663 minor = atoi(tmp);
665 break;
667 default:
668 major = 0;
669 minor = 9;
671 gl_info->driver_version = MAKEDWORD_VERSION(major, minor);
672 TRACE_(d3d_caps)("found driver version (%s)->%i.%i->(0x%08x)\n", debugstr_a(gl_string), major, minor, gl_info->driver_version);
673 /* Current Windows drivers have versions like 6.14.... (some older have an earlier version) */
674 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
675 } else {
676 FIXME("OpenGL driver did not return version information\n");
677 gl_info->driver_version = MAKEDWORD_VERSION(0, 0);
678 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
681 TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
684 * Initialize openGL extension related variables
685 * with Default values
687 memset(&gl_info->supported, 0, sizeof(gl_info->supported));
688 gl_info->max_buffers = 1;
689 gl_info->max_textures = 1;
690 gl_info->max_texture_stages = 1;
691 gl_info->max_fragment_samplers = 1;
692 gl_info->max_vertex_samplers = 0;
693 gl_info->max_combined_samplers = 0;
694 gl_info->max_sampler_stages = 1;
695 gl_info->ps_arb_version = PS_VERSION_NOT_SUPPORTED;
696 gl_info->ps_arb_max_temps = 0;
697 gl_info->ps_arb_max_instructions = 0;
698 gl_info->vs_arb_version = VS_VERSION_NOT_SUPPORTED;
699 gl_info->vs_arb_max_temps = 0;
700 gl_info->vs_arb_max_instructions = 0;
701 gl_info->vs_nv_version = VS_VERSION_NOT_SUPPORTED;
702 gl_info->vs_ati_version = VS_VERSION_NOT_SUPPORTED;
703 gl_info->vs_glsl_constantsF = 0;
704 gl_info->ps_glsl_constantsF = 0;
705 gl_info->vs_arb_constantsF = 0;
706 gl_info->ps_arb_constantsF = 0;
708 /* Retrieve opengl defaults */
709 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
710 gl_info->max_clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
711 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
713 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
714 gl_info->max_lights = gl_max;
715 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
717 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
718 gl_info->max_texture_size = gl_max;
719 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
721 glGetFloatv(GL_POINT_SIZE_RANGE, gl_floatv);
722 gl_info->max_pointsizemin = gl_floatv[0];
723 gl_info->max_pointsize = gl_floatv[1];
724 TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
726 glGetIntegerv(GL_AUX_BUFFERS, &gl_max);
727 gl_info->max_aux_buffers = gl_max;
728 TRACE_(d3d_caps)("Offscreen rendering support - number of aux buffers=%d\n", gl_max);
730 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
731 GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
732 TRACE_(d3d_caps)("GL_Extensions reported:\n");
734 if (NULL == GL_Extensions) {
735 ERR(" GL_Extensions returns NULL\n");
736 } else {
737 while (*GL_Extensions != 0x00) {
738 const char *Start;
739 char ThisExtn[256];
740 size_t len;
742 while (isspace(*GL_Extensions)) GL_Extensions++;
743 Start = GL_Extensions;
744 while (!isspace(*GL_Extensions) && *GL_Extensions != 0x00) {
745 GL_Extensions++;
748 len = GL_Extensions - Start;
749 if (len == 0 || len >= sizeof(ThisExtn))
750 continue;
752 memcpy(ThisExtn, Start, len);
753 ThisExtn[len] = '\0';
754 TRACE_(d3d_caps)("- %s\n", ThisExtn);
756 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
757 if (!strcmp(ThisExtn, EXTENSION_MAP[i].extension_string)) {
758 TRACE_(d3d_caps)(" FOUND: %s support\n", EXTENSION_MAP[i].extension_string);
759 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
760 break;
764 /* Now work out what GL support this card really has */
765 #define USE_GL_FUNC(type, pfn, ext, replace) { \
766 DWORD ver = ver_for_ext(ext); \
767 if(gl_info->supported[ext]) gl_info->pfn = (type) pwglGetProcAddress(#pfn); \
768 else if(ver && ver <= gl_info->gl_version) gl_info->pfn = (type) pwglGetProcAddress(#replace); \
769 else gl_info->pfn = NULL; \
771 GL_EXT_FUNCS_GEN;
772 #undef USE_GL_FUNC
774 #define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type) pwglGetProcAddress(#pfn);
775 WGL_EXT_FUNCS_GEN;
776 #undef USE_GL_FUNC
778 /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
779 * loading the functions, otherwise the code above will load the extension entry points instead of the
780 * core functions, which may not work
782 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
783 if (gl_info->supported[EXTENSION_MAP[i].extension] == FALSE &&
784 EXTENSION_MAP[i].version <= gl_info->gl_version && EXTENSION_MAP[i].version) {
785 TRACE_(d3d_caps)(" GL CORE: %s support\n", EXTENSION_MAP[i].extension_string);
786 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
790 if (gl_info->supported[APPLE_FENCE]) {
791 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
792 * The apple extension interacts with some other apple exts. Disable the NV
793 * extension if the apple one is support to prevent confusion in other parts
794 * of the code
796 gl_info->supported[NV_FENCE] = FALSE;
798 if (gl_info->supported[APPLE_FLOAT_PIXELS]) {
799 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
801 * The enums are the same:
802 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881A
803 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881B
804 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
805 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
806 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140B
808 if(!gl_info->supported[ARB_TEXTURE_FLOAT]) {
809 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels\n");
810 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
812 if(!gl_info->supported[ARB_HALF_FLOAT_PIXEL]) {
813 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels\n");
814 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
817 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) {
818 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
819 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
821 if (gl_info->supported[NV_TEXTURE_SHADER2]) {
822 /* GL_ATI_envmap_bumpmap won't play nice with texture shaders, so disable it
823 * Won't occur in any real world situation though
825 gl_info->supported[ATI_ENVMAP_BUMPMAP] = FALSE;
826 if(gl_info->supported[NV_REGISTER_COMBINERS]) {
827 /* Also disable ATI_FRAGMENT_SHADER if register combienrs and texture_shader2
828 * are supported. The nv extensions provide the same functionality as the
829 * ATI one, and a bit more(signed pixelformats)
831 gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
834 if (gl_info->supported[ARB_DRAW_BUFFERS]) {
835 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
836 gl_info->max_buffers = gl_max;
837 TRACE_(d3d_caps)("Max draw buffers: %u\n", gl_max);
839 if (gl_info->supported[ARB_MULTITEXTURE]) {
840 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
841 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
842 TRACE_(d3d_caps)("Max textures: %d\n", gl_info->max_textures);
844 if (gl_info->supported[NV_REGISTER_COMBINERS]) {
845 GLint tmp;
846 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &tmp);
847 gl_info->max_texture_stages = min(MAX_TEXTURES, tmp);
848 } else {
849 gl_info->max_texture_stages = min(MAX_TEXTURES, gl_max);
851 TRACE_(d3d_caps)("Max texture stages: %d\n", gl_info->max_texture_stages);
853 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
854 GLint tmp;
855 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
856 gl_info->max_fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
857 } else {
858 gl_info->max_fragment_samplers = max(gl_info->max_fragment_samplers, gl_max);
860 TRACE_(d3d_caps)("Max fragment samplers: %d\n", gl_info->max_fragment_samplers);
862 if (gl_info->supported[ARB_VERTEX_SHADER]) {
863 GLint tmp;
864 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
865 gl_info->max_vertex_samplers = tmp;
866 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
867 gl_info->max_combined_samplers = tmp;
869 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
870 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
871 * an issue because then the sampler setup only depends on the two shaders. If a pixel
872 * shader is used with fixed function vertex processing we're fine too because fixed function
873 * vertex processing doesn't use any samplers. If fixed function fragment processing is
874 * used we have to make sure that all vertex sampler setups are valid together with all
875 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
876 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
877 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
878 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
879 * a fixed function pipeline anymore.
881 * So this is just a check to check that our assumption holds true. If not, write a warning
882 * and reduce the number of vertex samplers or probably disable vertex texture fetch.
884 if(gl_info->max_vertex_samplers &&
885 MAX_TEXTURES + gl_info->max_vertex_samplers > gl_info->max_combined_samplers) {
886 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers\n",
887 gl_info->max_vertex_samplers, gl_info->max_combined_samplers);
888 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers\n");
889 if( gl_info->max_combined_samplers > MAX_TEXTURES )
890 gl_info->max_vertex_samplers =
891 gl_info->max_combined_samplers - MAX_TEXTURES;
892 else
893 gl_info->max_vertex_samplers = 0;
895 } else {
896 gl_info->max_combined_samplers = gl_info->max_fragment_samplers;
898 TRACE_(d3d_caps)("Max vertex samplers: %u\n", gl_info->max_vertex_samplers);
899 TRACE_(d3d_caps)("Max combined samplers: %u\n", gl_info->max_combined_samplers);
901 if (gl_info->supported[ARB_VERTEX_BLEND]) {
902 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
903 gl_info->max_blends = gl_max;
904 TRACE_(d3d_caps)("Max blends: %u\n", gl_info->max_blends);
906 if (gl_info->supported[EXT_TEXTURE3D]) {
907 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
908 gl_info->max_texture3d_size = gl_max;
909 TRACE_(d3d_caps)("Max texture3D size: %d\n", gl_info->max_texture3d_size);
911 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC]) {
912 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
913 gl_info->max_anisotropy = gl_max;
914 TRACE_(d3d_caps)("Max anisotropy: %d\n", gl_info->max_anisotropy);
916 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
917 gl_info->ps_arb_version = PS_VERSION_11;
918 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
919 gl_info->ps_arb_constantsF = gl_max;
920 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d\n", gl_info->ps_arb_constantsF);
921 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
922 gl_info->ps_arb_max_temps = gl_max;
923 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d\n", gl_info->ps_arb_max_temps);
924 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
925 gl_info->ps_arb_max_instructions = gl_max;
926 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d\n", gl_info->ps_arb_max_instructions);
928 if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
929 gl_info->vs_arb_version = VS_VERSION_11;
930 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
931 gl_info->vs_arb_constantsF = gl_max;
932 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d\n", gl_info->vs_arb_constantsF);
933 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
934 gl_info->vs_arb_max_temps = gl_max;
935 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d\n", gl_info->vs_arb_max_temps);
936 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
937 gl_info->vs_arb_max_instructions = gl_max;
938 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d\n", gl_info->vs_arb_max_instructions);
940 gl_info->arb_vs_offset_limit = test_arb_vs_offset_limit(gl_info);
942 if (gl_info->supported[ARB_VERTEX_SHADER]) {
943 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
944 gl_info->vs_glsl_constantsF = gl_max / 4;
945 TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u\n", gl_info->vs_glsl_constantsF);
947 if (gl_info->supported[ARB_FRAGMENT_SHADER]) {
948 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
949 gl_info->ps_glsl_constantsF = gl_max / 4;
950 TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u\n", gl_info->ps_glsl_constantsF);
951 glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
952 gl_info->max_glsl_varyings = gl_max;
953 TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings)\n", gl_max, gl_max / 4);
955 if (gl_info->supported[EXT_VERTEX_SHADER]) {
956 gl_info->vs_ati_version = VS_VERSION_11;
958 if (gl_info->supported[NV_VERTEX_PROGRAM3]) {
959 gl_info->vs_nv_version = VS_VERSION_30;
960 } else if (gl_info->supported[NV_VERTEX_PROGRAM2]) {
961 gl_info->vs_nv_version = VS_VERSION_20;
962 } else if (gl_info->supported[NV_VERTEX_PROGRAM1_1]) {
963 gl_info->vs_nv_version = VS_VERSION_11;
964 } else if (gl_info->supported[NV_VERTEX_PROGRAM]) {
965 gl_info->vs_nv_version = VS_VERSION_10;
967 if (gl_info->supported[NV_FRAGMENT_PROGRAM2]) {
968 gl_info->ps_nv_version = PS_VERSION_30;
969 } else if (gl_info->supported[NV_FRAGMENT_PROGRAM]) {
970 gl_info->ps_nv_version = PS_VERSION_20;
972 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT]) {
973 glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->max_shininess);
974 } else {
975 gl_info->max_shininess = 128.0;
977 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO]) {
978 /* If we have full NP2 texture support, disable GL_ARB_texture_rectangle because we will never use it.
979 * This saves a few redundant glDisable calls
981 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
983 if(gl_info->supported[ATI_FRAGMENT_SHADER]) {
984 /* Disable NV_register_combiners and fragment shader if this is supported.
985 * generally the NV extensions are prefered over the ATI one, and this
986 * extension is disabled if register_combiners and texture_shader2 are both
987 * supported. So we reach this place only if we have incomplete NV dxlevel 8
988 * fragment processing support
990 gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
991 gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
992 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
993 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
994 gl_info->supported[NV_TEXTURE_SHADER3] = FALSE;
998 checkGLcall("extension detection\n");
1000 /* In some cases the number of texture stages can be larger than the number
1001 * of samplers. The GF4 for example can use only 2 samplers (no fragment
1002 * shaders), but 8 texture stages (register combiners). */
1003 gl_info->max_sampler_stages = max(gl_info->max_fragment_samplers, gl_info->max_texture_stages);
1005 /* We can only use ORM_FBO when the hardware supports it. */
1006 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && !gl_info->supported[EXT_FRAMEBUFFER_OBJECT]) {
1007 WARN_(d3d_caps)("GL_EXT_framebuffer_object not supported, falling back to PBuffer offscreen rendering mode.\n");
1008 wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
1011 /* MRTs are currently only supported when FBOs are used. */
1012 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) {
1013 gl_info->max_buffers = 1;
1016 /* Below is a list of Nvidia and ATI GPUs. Both vendors have dozens of different GPUs with roughly the same
1017 * features. In most cases GPUs from a certain family differ in clockspeeds, the amount of video memory and
1018 * in case of the latest videocards in the number of pixel/vertex pipelines.
1020 * A Direct3D device object contains the PCI id (vendor + device) of the videocard which is used for
1021 * rendering. Various games use this information to get a rough estimation of the features of the card
1022 * and some might use it for enabling 3d effects only on certain types of videocards. In some cases
1023 * games might even use it to work around bugs which happen on certain videocards/driver combinations.
1024 * The problem is that OpenGL only exposes a rendering string containing the name of the videocard and
1025 * not the PCI id.
1027 * Various games depend on the PCI id, so somehow we need to provide one. A simple option is to parse
1028 * the renderer string and translate this to the right PCI id. This is a lot of work because there are more
1029 * than 200 GPUs just for Nvidia. Various cards share the same renderer string, so the amount of code might
1030 * be 'small' but there are quite a number of exceptions which would make this a pain to maintain.
1031 * Another way would be to query the PCI id from the operating system (assuming this is the videocard which
1032 * is used for rendering which is not always the case). This would work but it is not very portable. Second
1033 * it would not work well in, let's say, a remote X situation in which the amount of 3d features which can be used
1034 * is limited.
1036 * As said most games only use the PCI id to get an indication of the capabilities of the card.
1037 * It doesn't really matter if the given id is the correct one if we return the id of a card with
1038 * similar 3d features.
1040 * The code below checks the OpenGL capabilities of a videocard and matches that to a certain level of
1041 * Direct3D functionality. Once a card passes the Direct3D9 check, we know that the card (in case of Nvidia)
1042 * is at least a GeforceFX. To give a better estimate we do a basic check on the renderer string but if that
1043 * won't pass we return a default card. This way is better than maintaining a full card database as even
1044 * without a full database we can return a card with similar features. Second the size of the database
1045 * can be made quite small because when you know what type of 3d functionality a card has, you know to which
1046 * GPU family the GPU must belong. Because of this you only have to check a small part of the renderer string
1047 * to distinguishes between different models from that family.
1049 * The code also selects a default amount of video memory which we will use for an estimation of the amount
1050 * of free texture memory. In case of real D3D the amount of texture memory includes video memory and system
1051 * memory (to be specific AGP memory or in case of PCIE TurboCache/HyperMemory). We don't know how much
1052 * system memory can be addressed by the system but we can make a reasonable estimation about the amount of
1053 * video memory. If the value is slightly wrong it doesn't matter as we didn't include AGP-like memory which
1054 * makes the amount of addressable memory higher and second OpenGL isn't that critical it moves to system
1055 * memory behind our backs if really needed.
1056 * Note that the amount of video memory can be overruled using a registry setting.
1058 switch (gl_info->gl_vendor) {
1059 case VENDOR_NVIDIA:
1060 /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1061 * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1063 if(WINE_D3D9_CAPABLE(gl_info) && (gl_info->vs_nv_version == VS_VERSION_30)) {
1064 /* Geforce8 - highend */
1065 if (strstr(gl_info->gl_renderer, "8800")) {
1066 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8800GTS;
1067 vidmem = 320; /* The 8800GTS uses 320MB, a 8800GTX can have 768MB */
1069 /* Geforce8 - midend mobile */
1070 else if(strstr(gl_info->gl_renderer, "8600 M")) {
1071 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600MGT;
1072 vidmem = 512;
1074 /* Geforce8 - midend */
1075 else if(strstr(gl_info->gl_renderer, "8600") ||
1076 strstr(gl_info->gl_renderer, "8700"))
1078 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600GT;
1079 vidmem = 256;
1081 /* Geforce8 - lowend */
1082 else if(strstr(gl_info->gl_renderer, "8300") ||
1083 strstr(gl_info->gl_renderer, "8400") ||
1084 strstr(gl_info->gl_renderer, "8500"))
1086 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8300GS;
1087 vidmem = 128; /* 128-256MB for a 8300, 256-512MB for a 8400 */
1089 /* Geforce7 - highend */
1090 else if(strstr(gl_info->gl_renderer, "7800") ||
1091 strstr(gl_info->gl_renderer, "7900") ||
1092 strstr(gl_info->gl_renderer, "7950") ||
1093 strstr(gl_info->gl_renderer, "Quadro FX 4") ||
1094 strstr(gl_info->gl_renderer, "Quadro FX 5"))
1096 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7800GT;
1097 vidmem = 256; /* A 7800GT uses 256MB while highend 7900 cards can use 512MB */
1099 /* Geforce7 midend */
1100 else if(strstr(gl_info->gl_renderer, "7600") ||
1101 strstr(gl_info->gl_renderer, "7700")) {
1102 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7600;
1103 vidmem = 256; /* The 7600 uses 256-512MB */
1104 /* Geforce7 lower medium */
1105 } else if(strstr(gl_info->gl_renderer, "7400")) {
1106 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7400;
1107 vidmem = 256; /* The 7400 uses 256-512MB */
1109 /* Geforce7 lowend */
1110 else if(strstr(gl_info->gl_renderer, "7300")) {
1111 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7300;
1112 vidmem = 256; /* Mac Pros with this card have 256 MB */
1114 /* Geforce6 highend */
1115 else if(strstr(gl_info->gl_renderer, "6800"))
1117 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6800;
1118 vidmem = 128; /* The 6800 uses 128-256MB, the 7600 uses 256-512MB */
1120 /* Geforce6 - midend */
1121 else if(strstr(gl_info->gl_renderer, "6600") ||
1122 strstr(gl_info->gl_renderer, "6610") ||
1123 strstr(gl_info->gl_renderer, "6700"))
1125 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6600GT;
1126 vidmem = 128; /* A 6600GT has 128-256MB */
1128 /* Geforce6/7 lowend */
1129 else {
1130 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
1131 vidmem = 64; /* */
1133 } else if(WINE_D3D9_CAPABLE(gl_info)) {
1134 /* GeforceFX - highend */
1135 if (strstr(gl_info->gl_renderer, "5800") ||
1136 strstr(gl_info->gl_renderer, "5900") ||
1137 strstr(gl_info->gl_renderer, "5950") ||
1138 strstr(gl_info->gl_renderer, "Quadro FX"))
1140 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5800;
1141 vidmem = 256; /* 5800-5900 cards use 256MB */
1143 /* GeforceFX - midend */
1144 else if(strstr(gl_info->gl_renderer, "5600") ||
1145 strstr(gl_info->gl_renderer, "5650") ||
1146 strstr(gl_info->gl_renderer, "5700") ||
1147 strstr(gl_info->gl_renderer, "5750"))
1149 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1150 vidmem = 128; /* A 5600 uses 128-256MB */
1152 /* GeforceFX - lowend */
1153 else {
1154 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1155 vidmem = 64; /* Normal FX5200 cards use 64-256MB; laptop (non-standard) can have less */
1157 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1158 if (strstr(gl_info->gl_renderer, "GeForce4 Ti") || strstr(gl_info->gl_renderer, "Quadro4")) {
1159 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1160 vidmem = 64; /* Geforce4 Ti cards have 64-128MB */
1162 else {
1163 gl_info->gl_card = CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1164 vidmem = 64; /* Geforce3 cards have 64-128MB */
1166 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1167 if (strstr(gl_info->gl_renderer, "GeForce4 MX")) {
1168 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1169 vidmem = 64; /* Most Geforce4MX GPUs have at least 64MB of memory, some early models had 32MB but most have 64MB or even 128MB */
1171 else if(strstr(gl_info->gl_renderer, "GeForce2 MX") || strstr(gl_info->gl_renderer, "Quadro2 MXR")) {
1172 gl_info->gl_card = CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1173 vidmem = 32; /* Geforce2MX GPUs have 32-64MB of video memory */
1175 else if(strstr(gl_info->gl_renderer, "GeForce2") || strstr(gl_info->gl_renderer, "Quadro2")) {
1176 gl_info->gl_card = CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1177 vidmem = 32; /* Geforce2 GPUs have 32-64MB of video memory */
1179 else {
1180 gl_info->gl_card = CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1181 vidmem = 32; /* Most Geforce1 cards have 32MB, there are also some rare 16 and 64MB (Dell) models */
1183 } else {
1184 if (strstr(gl_info->gl_renderer, "TNT2")) {
1185 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1186 vidmem = 32; /* Most TNT2 boards have 32MB, though there are 16MB boards too */
1188 else {
1189 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1190 vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
1193 break;
1194 case VENDOR_ATI:
1195 if(WINE_D3D9_CAPABLE(gl_info)) {
1196 /* Radeon R6xx HD2900 - highend */
1197 if (strstr(gl_info->gl_renderer, "HD 2900")) {
1198 gl_info->gl_card = CARD_ATI_RADEON_HD2900;
1199 vidmem = 512; /* HD2900 uses 512-1024MB */
1201 /* Radeon R6xx HD2600- midend */
1202 else if (strstr(gl_info->gl_renderer, "HD 2600")) {
1203 gl_info->gl_card = CARD_ATI_RADEON_HD2600;
1204 vidmem = 256; /* HD2600 uses 256-512MB */
1206 /* Radeon R6xx HD2300/HD2400 - lowend */
1207 else if (strstr(gl_info->gl_renderer, "HD 2300") ||
1208 strstr(gl_info->gl_renderer, "HD 2400"))
1210 gl_info->gl_card = CARD_ATI_RADEON_HD2300;
1211 vidmem = 128; /* HD2300 uses at least 128MB, HD2400 uses 256MB */
1213 /* Radeon R5xx */
1214 else if (strstr(gl_info->gl_renderer, "X1600") ||
1215 strstr(gl_info->gl_renderer, "X1650") ||
1216 strstr(gl_info->gl_renderer, "X1800") ||
1217 strstr(gl_info->gl_renderer, "X1900") ||
1218 strstr(gl_info->gl_renderer, "X1950"))
1220 gl_info->gl_card = CARD_ATI_RADEON_X1600;
1221 vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
1223 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
1224 else if(strstr(gl_info->gl_renderer, "X700") ||
1225 strstr(gl_info->gl_renderer, "X800") ||
1226 strstr(gl_info->gl_renderer, "X850") ||
1227 strstr(gl_info->gl_renderer, "X1300") ||
1228 strstr(gl_info->gl_renderer, "X1400") ||
1229 strstr(gl_info->gl_renderer, "X1450") ||
1230 strstr(gl_info->gl_renderer, "X1550"))
1232 gl_info->gl_card = CARD_ATI_RADEON_X700;
1233 vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
1235 /* Radeon R3xx */
1236 else {
1237 gl_info->gl_card = CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
1238 vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
1240 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1241 gl_info->gl_card = CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
1242 vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
1243 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1244 gl_info->gl_card = CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
1245 vidmem = 32; /* There are models with up to 64MB */
1246 } else {
1247 gl_info->gl_card = CARD_ATI_RAGE_128PRO;
1248 vidmem = 16; /* There are 16-32MB models */
1250 break;
1251 case VENDOR_INTEL:
1252 if (strstr(gl_info->gl_renderer, "GMA 950")) {
1253 /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */
1254 gl_info->gl_card = CARD_INTEL_I945GM;
1255 vidmem = 64;
1256 } else if (strstr(gl_info->gl_renderer, "915GM")) {
1257 gl_info->gl_card = CARD_INTEL_I915GM;
1258 } else if (strstr(gl_info->gl_renderer, "915G")) {
1259 gl_info->gl_card = CARD_INTEL_I915G;
1260 } else if (strstr(gl_info->gl_renderer, "865G")) {
1261 gl_info->gl_card = CARD_INTEL_I865G;
1262 } else if (strstr(gl_info->gl_renderer, "855G")) {
1263 gl_info->gl_card = CARD_INTEL_I855G;
1264 } else if (strstr(gl_info->gl_renderer, "830G")) {
1265 gl_info->gl_card = CARD_INTEL_I830G;
1266 } else {
1267 gl_info->gl_card = CARD_INTEL_I915G;
1269 break;
1270 case VENDOR_MESA:
1271 case VENDOR_WINE:
1272 default:
1273 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice
1274 * for Nvidia was because the hardware and drivers they make are of good quality. This makes
1275 * them a good generic choice.
1277 gl_info->gl_vendor = VENDOR_NVIDIA;
1278 if(WINE_D3D9_CAPABLE(gl_info))
1279 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1280 else if(WINE_D3D8_CAPABLE(gl_info))
1281 gl_info->gl_card = CARD_NVIDIA_GEFORCE3;
1282 else if(WINE_D3D7_CAPABLE(gl_info))
1283 gl_info->gl_card = CARD_NVIDIA_GEFORCE;
1284 else if(WINE_D3D6_CAPABLE(gl_info))
1285 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT;
1286 else
1287 gl_info->gl_card = CARD_NVIDIA_RIVA_128;
1289 TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card);
1291 /* If we have an estimate use it, else default to 64MB; */
1292 if(vidmem)
1293 gl_info->vidmem = vidmem*1024*1024; /* convert from MBs to bytes */
1294 else
1295 gl_info->vidmem = WINE_DEFAULT_VIDMEM;
1297 /* Load all the lookup tables
1298 TODO: It may be a good idea to make minLookup and maxLookup const and populate them in wined3d_private.h where they are declared */
1299 minLookup[WINELOOKUP_WARPPARAM] = WINED3DTADDRESS_WRAP;
1300 maxLookup[WINELOOKUP_WARPPARAM] = WINED3DTADDRESS_MIRRORONCE;
1302 minLookup[WINELOOKUP_MAGFILTER] = WINED3DTEXF_NONE;
1303 maxLookup[WINELOOKUP_MAGFILTER] = WINED3DTEXF_ANISOTROPIC;
1306 for (i = 0; i < MAX_LOOKUPS; i++) {
1307 stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
1310 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
1311 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
1312 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1313 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1314 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1315 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1316 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
1317 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
1318 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
1319 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
1321 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_NONE - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
1322 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_POINT - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
1323 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_LINEAR - minLookup[WINELOOKUP_MAGFILTER]] = GL_LINEAR;
1324 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_ANISOTROPIC - minLookup[WINELOOKUP_MAGFILTER]] =
1325 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR : GL_NEAREST;
1328 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_NONE] = GL_LINEAR;
1329 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_POINT] = GL_LINEAR;
1330 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_LINEAR] = GL_LINEAR;
1331 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_NONE] = GL_NEAREST;
1332 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_POINT] = GL_NEAREST_MIPMAP_NEAREST;
1333 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_LINEAR] = GL_NEAREST_MIPMAP_LINEAR;
1334 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_NONE] = GL_LINEAR;
1335 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_POINT] = GL_LINEAR_MIPMAP_NEAREST;
1336 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_LINEAR] = GL_LINEAR_MIPMAP_LINEAR;
1337 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_NONE] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ?
1338 GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1339 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_POINT] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR;
1340 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_LINEAR] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1342 /* TODO: config lookups */
1344 /* Make sure there's an active HDC else the WGL extensions will fail */
1345 hdc = pwglGetCurrentDC();
1346 if (hdc) {
1347 WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc));
1348 TRACE_(d3d_caps)("WGL_Extensions reported:\n");
1350 if (NULL == WGL_Extensions) {
1351 ERR(" WGL_Extensions returns NULL\n");
1352 } else {
1353 while (*WGL_Extensions != 0x00) {
1354 const char *Start;
1355 char ThisExtn[256];
1356 size_t len;
1358 while (isspace(*WGL_Extensions)) WGL_Extensions++;
1359 Start = WGL_Extensions;
1360 while (!isspace(*WGL_Extensions) && *WGL_Extensions != 0x00) {
1361 WGL_Extensions++;
1364 len = WGL_Extensions - Start;
1365 if (len == 0 || len >= sizeof(ThisExtn))
1366 continue;
1368 memcpy(ThisExtn, Start, len);
1369 ThisExtn[len] = '\0';
1370 TRACE_(d3d_caps)("- %s\n", ThisExtn);
1372 if (!strcmp(ThisExtn, "WGL_ARB_pbuffer")) {
1373 gl_info->supported[WGL_ARB_PBUFFER] = TRUE;
1374 TRACE_(d3d_caps)("FOUND: WGL_ARB_pbuffer support\n");
1379 LEAVE_GL();
1381 return return_value;
1383 #undef GLINFO_LOCATION
1385 /**********************************************************
1386 * IWineD3D implementation follows
1387 **********************************************************/
1389 static UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
1390 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1392 TRACE_(d3d_caps)("(%p): Reporting %d adapters\n", This, numAdapters);
1393 return numAdapters;
1396 static HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
1397 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1398 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
1399 return WINED3D_OK;
1402 static HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
1403 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1405 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
1406 return NULL;
1409 TRACE_(d3d_caps)("(%p)->(%d)\n", This, Adapter);
1410 return MonitorFromPoint(Adapters[Adapter].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
1413 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
1414 of the same bpp but different resolutions */
1416 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1417 static UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
1418 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1419 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
1421 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1422 return 0;
1425 /* TODO: Store modes per adapter and read it from the adapter structure */
1426 if (Adapter == 0) { /* Display */
1427 int i = 0;
1428 int j = 0;
1430 if (!DEBUG_SINGLE_MODE) {
1431 DEVMODEW DevModeW;
1433 ZeroMemory(&DevModeW, sizeof(DevModeW));
1434 DevModeW.dmSize = sizeof(DevModeW);
1435 while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
1436 j++;
1437 switch (Format)
1439 case WINED3DFMT_UNKNOWN:
1440 /* This is for D3D8, do not enumerate P8 here */
1441 if (DevModeW.dmBitsPerPel == 32 ||
1442 DevModeW.dmBitsPerPel == 16) i++;
1443 break;
1444 case WINED3DFMT_X8R8G8B8:
1445 if (DevModeW.dmBitsPerPel == 32) i++;
1446 break;
1447 case WINED3DFMT_R5G6B5:
1448 if (DevModeW.dmBitsPerPel == 16) i++;
1449 break;
1450 case WINED3DFMT_P8:
1451 if (DevModeW.dmBitsPerPel == 8) i++;
1452 break;
1453 default:
1454 /* Skip other modes as they do not match the requested format */
1455 break;
1458 } else {
1459 i = 1;
1460 j = 1;
1463 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
1464 return i;
1465 } else {
1466 FIXME_(d3d_caps)("Adapter not primary display\n");
1468 return 0;
1471 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1472 static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, WINED3DDISPLAYMODE* pMode) {
1473 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1474 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
1476 /* Validate the parameters as much as possible */
1477 if (NULL == pMode ||
1478 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
1479 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
1480 return WINED3DERR_INVALIDCALL;
1483 /* TODO: Store modes per adapter and read it from the adapter structure */
1484 if (Adapter == 0 && !DEBUG_SINGLE_MODE) { /* Display */
1485 DEVMODEW DevModeW;
1486 int ModeIdx = 0;
1487 int i = 0;
1488 int j = 0;
1490 ZeroMemory(&DevModeW, sizeof(DevModeW));
1491 DevModeW.dmSize = sizeof(DevModeW);
1493 /* If we are filtering to a specific format (D3D9), then need to skip
1494 all unrelated modes, but if mode is irrelevant (D3D8), then we can
1495 just count through the ones with valid bit depths */
1496 while ((i<=Mode) && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0)) {
1497 switch (Format)
1499 case WINED3DFMT_UNKNOWN:
1500 /* This is D3D8. Do not enumerate P8 here */
1501 if (DevModeW.dmBitsPerPel == 32 ||
1502 DevModeW.dmBitsPerPel == 16) i++;
1503 break;
1504 case WINED3DFMT_X8R8G8B8:
1505 if (DevModeW.dmBitsPerPel == 32) i++;
1506 break;
1507 case WINED3DFMT_R5G6B5:
1508 if (DevModeW.dmBitsPerPel == 16) i++;
1509 break;
1510 case WINED3DFMT_P8:
1511 if (DevModeW.dmBitsPerPel == 8) i++;
1512 break;
1513 default:
1514 /* Modes that don't match what we support can get an early-out */
1515 TRACE_(d3d_caps)("Searching for %s, returning D3DERR_INVALIDCALL\n", debug_d3dformat(Format));
1516 return WINED3DERR_INVALIDCALL;
1520 if (i == 0) {
1521 TRACE_(d3d_caps)("No modes found for format (%x - %s)\n", Format, debug_d3dformat(Format));
1522 return WINED3DERR_INVALIDCALL;
1524 ModeIdx = j - 1;
1526 /* Now get the display mode via the calculated index */
1527 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0)) {
1528 pMode->Width = DevModeW.dmPelsWidth;
1529 pMode->Height = DevModeW.dmPelsHeight;
1530 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1531 if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
1532 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1534 if (Format == WINED3DFMT_UNKNOWN) {
1535 pMode->Format = pixelformat_for_depth(DevModeW.dmBitsPerPel);
1536 } else {
1537 pMode->Format = Format;
1539 } else {
1540 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
1541 return WINED3DERR_INVALIDCALL;
1544 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
1545 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format),
1546 DevModeW.dmBitsPerPel);
1548 } else if (DEBUG_SINGLE_MODE) {
1549 /* Return one setting of the format requested */
1550 if (Mode > 0) return WINED3DERR_INVALIDCALL;
1551 pMode->Width = 800;
1552 pMode->Height = 600;
1553 pMode->RefreshRate = 60;
1554 pMode->Format = (Format == WINED3DFMT_UNKNOWN) ? WINED3DFMT_X8R8G8B8 : Format;
1555 } else {
1556 FIXME_(d3d_caps)("Adapter not primary display\n");
1559 return WINED3D_OK;
1562 static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, WINED3DDISPLAYMODE* pMode) {
1563 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1564 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
1566 if (NULL == pMode ||
1567 Adapter >= IWineD3D_GetAdapterCount(iface)) {
1568 return WINED3DERR_INVALIDCALL;
1571 if (Adapter == 0) { /* Display */
1572 int bpp = 0;
1573 DEVMODEW DevModeW;
1575 ZeroMemory(&DevModeW, sizeof(DevModeW));
1576 DevModeW.dmSize = sizeof(DevModeW);
1578 EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &DevModeW, 0);
1579 pMode->Width = DevModeW.dmPelsWidth;
1580 pMode->Height = DevModeW.dmPelsHeight;
1581 bpp = DevModeW.dmBitsPerPel;
1582 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1583 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
1585 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1588 pMode->Format = pixelformat_for_depth(bpp);
1589 } else {
1590 FIXME_(d3d_caps)("Adapter not primary display\n");
1593 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
1594 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
1595 return WINED3D_OK;
1598 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
1599 and fields being inserted in the middle, a new structure is used in place */
1600 static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
1601 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
1602 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1604 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %x, pId=%p)\n", This, Adapter, Flags, pIdentifier);
1606 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1607 return WINED3DERR_INVALIDCALL;
1610 /* Return the information requested */
1611 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
1612 strcpy(pIdentifier->Driver, Adapters[Adapter].driver);
1613 strcpy(pIdentifier->Description, Adapters[Adapter].description);
1615 /* Note dx8 doesn't supply a DeviceName */
1616 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
1617 pIdentifier->DriverVersion->u.HighPart = Adapters[Adapter].gl_info.driver_version_hipart;
1618 pIdentifier->DriverVersion->u.LowPart = Adapters[Adapter].gl_info.driver_version;
1619 *(pIdentifier->VendorId) = Adapters[Adapter].gl_info.gl_vendor;
1620 *(pIdentifier->DeviceId) = Adapters[Adapter].gl_info.gl_card;
1621 *(pIdentifier->SubSysId) = 0;
1622 *(pIdentifier->Revision) = 0;
1623 *pIdentifier->DeviceIdentifier = IID_D3DDEVICE_D3DUID;
1625 if (Flags & WINED3DENUM_NO_WHQL_LEVEL) {
1626 *(pIdentifier->WHQLLevel) = 0;
1627 } else {
1628 *(pIdentifier->WHQLLevel) = 1;
1631 return WINED3D_OK;
1634 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const WineD3D_PixelFormat *cfg, WINED3DFORMAT Format) {
1635 short redSize, greenSize, blueSize, alphaSize, colorBits;
1637 if(!cfg)
1638 return FALSE;
1640 if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */
1641 if(!getColorBits(Format, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits)) {
1642 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(Format));
1643 return FALSE;
1646 if(cfg->redSize < redSize)
1647 return FALSE;
1649 if(cfg->greenSize < greenSize)
1650 return FALSE;
1652 if(cfg->blueSize < blueSize)
1653 return FALSE;
1655 if(cfg->alphaSize < alphaSize)
1656 return FALSE;
1658 return TRUE;
1659 } else if(cfg->iPixelType == WGL_TYPE_RGBA_FLOAT_ARB) { /* Float RGBA formats; TODO: WGL_NV_float_buffer */
1660 if(Format == WINED3DFMT_R16F)
1661 return (cfg->redSize == 16 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1662 if(Format == WINED3DFMT_G16R16F)
1663 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1664 if(Format == WINED3DFMT_A16B16G16R16F)
1665 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 16 && cfg->alphaSize == 16);
1666 if(Format == WINED3DFMT_R32F)
1667 return (cfg->redSize == 32 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1668 if(Format == WINED3DFMT_G32R32F)
1669 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1670 if(Format == WINED3DFMT_A32B32G32R32F)
1671 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 32 && cfg->alphaSize == 32);
1672 } else {
1673 /* Probably a color index mode */
1674 return FALSE;
1677 return FALSE;
1680 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const WineD3D_PixelFormat *cfg, WINED3DFORMAT Format) {
1681 short depthSize, stencilSize;
1682 BOOL lockable = FALSE;
1684 if(!cfg)
1685 return FALSE;
1687 if(!getDepthStencilBits(Format, &depthSize, &stencilSize)) {
1688 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(Format));
1689 return FALSE;
1692 if((Format == WINED3DFMT_D16_LOCKABLE) || (Format == WINED3DFMT_D32F_LOCKABLE))
1693 lockable = TRUE;
1695 /* On some modern cards like the Geforce8/9 GLX doesn't offer some dephthstencil formats which D3D9 reports.
1696 * We can safely report 'compatible' formats (e.g. D24 can be used for D16) as long as we aren't dealing with
1697 * a lockable format. This also helps D3D <= 7 as they expect D16 which isn't offered without this on Geforce8 cards. */
1698 if(!(cfg->depthSize == depthSize || (!lockable && cfg->depthSize > depthSize)))
1699 return FALSE;
1701 if(cfg->stencilSize != stencilSize)
1702 return FALSE;
1704 return TRUE;
1707 static HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1708 WINED3DFORMAT AdapterFormat,
1709 WINED3DFORMAT RenderTargetFormat,
1710 WINED3DFORMAT DepthStencilFormat) {
1711 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1712 int nCfgs;
1713 WineD3D_PixelFormat *cfgs;
1714 int it;
1716 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
1717 This, Adapter,
1718 DeviceType, debug_d3ddevicetype(DeviceType),
1719 AdapterFormat, debug_d3dformat(AdapterFormat),
1720 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
1721 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
1723 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1724 TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning WINED3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
1725 return WINED3DERR_INVALIDCALL;
1728 cfgs = Adapters[Adapter].cfgs;
1729 nCfgs = Adapters[Adapter].nCfgs;
1730 for (it = 0; it < nCfgs; ++it) {
1731 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], RenderTargetFormat)) {
1732 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&cfgs[it], DepthStencilFormat)) {
1733 TRACE_(d3d_caps)("(%p) : Formats matched\n", This);
1734 return WINED3D_OK;
1738 WARN_(d3d_caps)("unsupported format pair: %s and %s\n", debug_d3dformat(RenderTargetFormat), debug_d3dformat(DepthStencilFormat));
1740 return WINED3DERR_NOTAVAILABLE;
1743 static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1744 WINED3DFORMAT SurfaceFormat,
1745 BOOL Windowed, WINED3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
1747 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1748 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
1749 This,
1750 Adapter,
1751 DeviceType, debug_d3ddevicetype(DeviceType),
1752 SurfaceFormat, debug_d3dformat(SurfaceFormat),
1753 Windowed,
1754 MultiSampleType,
1755 pQualityLevels);
1757 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1758 return WINED3DERR_INVALIDCALL;
1761 /* TODO: Store in Adapter structure */
1762 if (pQualityLevels != NULL) {
1763 static int s_single_shot = 0;
1764 if (!s_single_shot) {
1765 FIXME("Quality levels unsupported at present\n");
1766 s_single_shot = 1;
1768 *pQualityLevels = 1; /* Guess at a value! */
1771 if (WINED3DMULTISAMPLE_NONE == MultiSampleType) return WINED3D_OK;
1772 return WINED3DERR_NOTAVAILABLE;
1775 static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1776 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
1778 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1779 HRESULT hr = WINED3DERR_NOTAVAILABLE;
1780 UINT nmodes;
1782 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
1783 This,
1784 Adapter,
1785 DeviceType, debug_d3ddevicetype(DeviceType),
1786 DisplayFormat, debug_d3dformat(DisplayFormat),
1787 BackBufferFormat, debug_d3dformat(BackBufferFormat),
1788 Windowed);
1790 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1791 WARN_(d3d_caps)("Adapter >= IWineD3D_GetAdapterCount(iface), returning WINED3DERR_INVALIDCALL\n");
1792 return WINED3DERR_INVALIDCALL;
1795 /* The task of this function is to check whether a certain display / backbuffer format
1796 * combination is available on the given adapter. In fullscreen mode microsoft specified
1797 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
1798 * and display format should match exactly.
1799 * In windowed mode format conversion can occur and this depends on the driver. When format
1800 * conversion is done, this function should nevertheless fail and applications need to use
1801 * CheckDeviceFormatConversion.
1802 * At the moment we assume that fullscreen and windowed have the same capabilities */
1804 /* There are only 4 display formats */
1805 if(!((DisplayFormat == WINED3DFMT_R5G6B5) ||
1806 (DisplayFormat == WINED3DFMT_X1R5G5B5) ||
1807 (DisplayFormat == WINED3DFMT_X8R8G8B8) ||
1808 (DisplayFormat == WINED3DFMT_A2R10G10B10)))
1810 TRACE_(d3d_caps)("Format %s unsupported as display format\n", debug_d3dformat(DisplayFormat));
1811 return WINED3DERR_NOTAVAILABLE;
1814 /* If the requested DisplayFormat is not available, don't continue */
1815 nmodes = IWineD3DImpl_GetAdapterModeCount(iface, Adapter, DisplayFormat);
1816 if(!nmodes) {
1817 TRACE_(d3d_caps)("No available modes for display format %s\n", debug_d3dformat(DisplayFormat));
1818 return WINED3DERR_NOTAVAILABLE;
1821 /* Windowed mode allows you to specify WINED3DFMT_UNKNOWN for the backbufferformat, it means 'reuse' the display format for the backbuffer */
1822 if(!Windowed && BackBufferFormat == WINED3DFMT_UNKNOWN) {
1823 TRACE_(d3d_caps)("BackBufferFormat WINED3FMT_UNKNOWN not available in Windowed mode\n");
1824 return WINED3DERR_NOTAVAILABLE;
1827 /* In FULLSCREEN mode R5G6B5 can only be mixed with backbuffer format R5G6B5 */
1828 if( (DisplayFormat == WINED3DFMT_R5G6B5) && (BackBufferFormat != WINED3DFMT_R5G6B5) ) {
1829 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1830 return WINED3DERR_NOTAVAILABLE;
1833 /* In FULLSCREEN mode X1R5G5B5 can only be mixed with backbuffer format *1R5G5B5 */
1834 if( (DisplayFormat == WINED3DFMT_X1R5G5B5) && !((BackBufferFormat == WINED3DFMT_X1R5G5B5) || (BackBufferFormat == WINED3DFMT_A1R5G5B5)) ) {
1835 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1836 return WINED3DERR_NOTAVAILABLE;
1839 /* In FULLSCREEN mode X8R8G8B8 can only be mixed with backbuffer format *8R8G8B8 */
1840 if( (DisplayFormat == WINED3DFMT_X8R8G8B8) && !((BackBufferFormat == WINED3DFMT_X8R8G8B8) || (BackBufferFormat == WINED3DFMT_A8R8G8B8)) ) {
1841 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1842 return WINED3DERR_NOTAVAILABLE;
1845 /* A2R10G10B10 is only allowed in fullscreen mode and it can only be mixed with backbuffer format A2R10G10B10 */
1846 if( (DisplayFormat == WINED3DFMT_A2R10G10B10) && ((BackBufferFormat != WINED3DFMT_A2R10G10B10) || Windowed)) {
1847 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1848 return WINED3DERR_NOTAVAILABLE;
1851 /* Use CheckDeviceFormat to see if the BackBufferFormat is usable with the given DisplayFormat */
1852 hr = IWineD3DImpl_CheckDeviceFormat(iface, Adapter, DeviceType, DisplayFormat, WINED3DUSAGE_RENDERTARGET, WINED3DRTYPE_SURFACE, BackBufferFormat);
1853 if(FAILED(hr))
1854 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1856 return hr;
1860 #define GLINFO_LOCATION Adapters[Adapter].gl_info
1861 /* Check if we support bumpmapping for a format */
1862 static BOOL CheckBumpMapCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
1864 if(GL_SUPPORT(NV_REGISTER_COMBINERS) && GL_SUPPORT(NV_TEXTURE_SHADER2)) {
1865 switch (CheckFormat) {
1866 case WINED3DFMT_V8U8:
1867 TRACE_(d3d_caps)("[OK]\n");
1868 return TRUE;
1869 /* TODO: Other bump map formats */
1870 default:
1871 TRACE_(d3d_caps)("[FAILED]\n");
1872 return FALSE;
1875 if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP) || GL_SUPPORT(ATI_FRAGMENT_SHADER)) {
1876 switch (CheckFormat) {
1877 case WINED3DFMT_V8U8:
1878 TRACE_(d3d_caps)("[OK]\n");
1879 return TRUE;
1880 default:
1881 TRACE_(d3d_caps)("[FAILED]\n");
1882 return FALSE;
1885 TRACE_(d3d_caps)("[FAILED]\n");
1886 return FALSE;
1889 /* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
1890 static BOOL CheckDepthStencilCapability(UINT Adapter, WINED3DFORMAT DisplayFormat,
1891 WINED3DFORMAT DepthStencilFormat)
1893 int it=0;
1894 WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
1896 /* Only allow depth/stencil formats */
1897 switch (DepthStencilFormat) {
1898 case WINED3DFMT_D16_LOCKABLE:
1899 case WINED3DFMT_D16:
1900 case WINED3DFMT_D15S1:
1901 case WINED3DFMT_D24X8:
1902 case WINED3DFMT_D24X4S4:
1903 case WINED3DFMT_D24S8:
1904 case WINED3DFMT_D24FS8:
1905 case WINED3DFMT_D32:
1906 case WINED3DFMT_D32F_LOCKABLE:
1907 break;
1909 default:
1910 return FALSE;
1913 /* Walk through all WGL pixel formats to find a match */
1914 cfgs = Adapters[Adapter].cfgs;
1915 for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
1916 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], DisplayFormat)) {
1917 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&cfgs[it], DepthStencilFormat)) {
1918 return TRUE;
1923 return FALSE;
1926 static BOOL CheckFilterCapability(WINED3DFORMAT CheckFormat)
1928 switch (CheckFormat) {
1929 /* Filtering not supported */
1930 case WINED3DFMT_R32F:
1931 case WINED3DFMT_A32B32G32R32F:
1932 TRACE_(d3d_caps)("[FAILED]\n");
1933 return FALSE;
1934 default:
1935 break;
1938 return TRUE;
1941 /* Check the render target capabilities of a format */
1942 static BOOL CheckRenderTargetCapability(WINED3DFORMAT AdapterFormat, WINED3DFORMAT CheckFormat)
1944 UINT Adapter = 0;
1946 /* Filter out non-RT formats */
1947 switch(CheckFormat)
1949 /* Don't offer 8bit, windows doesn't either although we could emulate it */
1950 case WINED3DFMT_A8P8:
1951 case WINED3DFMT_P8:
1953 /* No DXTC render targets */
1954 case WINED3DFMT_DXT1:
1955 case WINED3DFMT_DXT2:
1956 case WINED3DFMT_DXT3:
1957 case WINED3DFMT_DXT4:
1958 case WINED3DFMT_DXT5:
1959 return FALSE;
1960 default:
1961 break;
1964 if(wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) {
1965 WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
1966 int it;
1967 short AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
1968 short CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
1970 getColorBits(AdapterFormat, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
1971 getColorBits(CheckFormat, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
1973 /* In backbuffer mode the front and backbuffer share the same WGL pixelformat.
1974 * The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */
1975 if(!((AdapterRed == CheckRed) && (AdapterGreen == CheckGreen) && (AdapterBlue == CheckBlue))) {
1976 TRACE_(d3d_caps)("[FAILED]\n");
1977 return FALSE;
1980 /* Check if there is a WGL pixel format matching the requirements, the format should also be window
1981 * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
1982 for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
1983 if (cfgs[it].windowDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], CheckFormat)) {
1984 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n", cfgs[it].iPixelFormat, debug_d3dformat(CheckFormat));
1985 return TRUE;
1988 } else if(wined3d_settings.offscreen_rendering_mode == ORM_PBUFFER) {
1989 /* We can propably use this function in FBO mode too on some drivers to get some basic indication of the capabilities. */
1990 WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
1991 int it;
1993 /* Check if there is a WGL pixel format matching the requirements, the pixel format should also be usable with pbuffers */
1994 for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
1995 if (cfgs[it].pbufferDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], CheckFormat)) {
1996 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n", cfgs[it].iPixelFormat, debug_d3dformat(CheckFormat));
1997 return TRUE;
2000 } else if(wined3d_settings.offscreen_rendering_mode == ORM_FBO){
2001 /* For now return TRUE for FBOs until we have some proper checks.
2002 * Note that this function will only be called when the format is around for texturing. */
2003 return TRUE;
2005 return FALSE;
2008 static BOOL CheckSrgbReadCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2010 /* Check for supported sRGB formats (Texture loading and framebuffer) */
2011 if(!GL_SUPPORT(EXT_TEXTURE_SRGB)) {
2012 TRACE_(d3d_caps)("[FAILED] GL_EXT_texture_sRGB not supported\n");
2013 return FALSE;
2016 switch (CheckFormat) {
2017 case WINED3DFMT_A8R8G8B8:
2018 case WINED3DFMT_X8R8G8B8:
2019 case WINED3DFMT_A4R4G4B4:
2020 case WINED3DFMT_L8:
2021 case WINED3DFMT_A8L8:
2022 case WINED3DFMT_DXT1:
2023 case WINED3DFMT_DXT2:
2024 case WINED3DFMT_DXT3:
2025 case WINED3DFMT_DXT4:
2026 case WINED3DFMT_DXT5:
2027 TRACE_(d3d_caps)("[OK]\n");
2028 return TRUE;
2030 default:
2031 TRACE_(d3d_caps)("[FAILED] Gamma texture format %s not supported.\n", debug_d3dformat(CheckFormat));
2032 return FALSE;
2034 return FALSE;
2037 static BOOL CheckSrgbWriteCapability(UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT CheckFormat)
2039 /* Only offer SRGB writing on X8R8G8B8/A8R8G8B8 when we use ARB or GLSL shaders as we are
2040 * doing the color fixup in shaders.
2041 * Note Windows drivers (at least on the Geforce 8800) also offer this on R5G6B5. */
2042 if((CheckFormat == WINED3DFMT_X8R8G8B8) || (CheckFormat == WINED3DFMT_A8R8G8B8)) {
2043 int vs_selected_mode;
2044 int ps_selected_mode;
2045 select_shader_mode(&GLINFO_LOCATION, DeviceType, &ps_selected_mode, &vs_selected_mode);
2047 if((ps_selected_mode == SHADER_ARB) || (ps_selected_mode == SHADER_GLSL)) {
2048 TRACE_(d3d_caps)("[OK]\n");
2049 return TRUE;
2053 TRACE_(d3d_caps)("[FAILED] - no SRGB writing support on format=%s\n", debug_d3dformat(CheckFormat));
2054 return FALSE;
2057 /* Check if a format support blending in combination with pixel shaders */
2058 static BOOL CheckPostPixelShaderBlendingCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2060 const GlPixelFormatDesc *glDesc;
2061 const StaticPixelFormatDesc *desc = getFormatDescEntry(CheckFormat, &GLINFO_LOCATION, &glDesc);
2063 /* Fail if we weren't able to get a description of the format */
2064 if(!desc || !glDesc)
2065 return FALSE;
2067 /* The flags entry of a format contains the post pixel shader blending capability */
2068 if(glDesc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)
2069 return TRUE;
2071 return FALSE;
2074 /* Check if a texture format is supported on the given adapter */
2075 static BOOL CheckTextureCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2077 switch (CheckFormat) {
2079 /*****
2080 * supported: RGB(A) formats
2082 case WINED3DFMT_R8G8B8: /* Enable for dx7, blacklisted for 8 and 9 above */
2083 case WINED3DFMT_A8R8G8B8:
2084 case WINED3DFMT_X8R8G8B8:
2085 case WINED3DFMT_R5G6B5:
2086 case WINED3DFMT_X1R5G5B5:
2087 case WINED3DFMT_A1R5G5B5:
2088 case WINED3DFMT_A4R4G4B4:
2089 case WINED3DFMT_R3G3B2:
2090 case WINED3DFMT_A8:
2091 case WINED3DFMT_X4R4G4B4:
2092 case WINED3DFMT_A8B8G8R8:
2093 case WINED3DFMT_X8B8G8R8:
2094 case WINED3DFMT_A2R10G10B10:
2095 case WINED3DFMT_A2B10G10R10:
2096 case WINED3DFMT_G16R16:
2097 TRACE_(d3d_caps)("[OK]\n");
2098 return TRUE;
2100 /*****
2101 * supported: Palettized
2103 case WINED3DFMT_P8:
2104 TRACE_(d3d_caps)("[OK]\n");
2105 return TRUE;
2106 /* No Windows driver offers A8P8, so don't offer it either */
2107 case WINED3DFMT_A8P8:
2108 return FALSE;
2110 /*****
2111 * Supported: (Alpha)-Luminance
2113 case WINED3DFMT_L8:
2114 case WINED3DFMT_A8L8:
2115 case WINED3DFMT_A4L4:
2116 case WINED3DFMT_L16:
2117 TRACE_(d3d_caps)("[OK]\n");
2118 return TRUE;
2120 /* Depth/stencil is handled using checkDepthStencilCapability, return FALSE here */
2121 case WINED3DFMT_D16_LOCKABLE:
2122 case WINED3DFMT_D16:
2123 case WINED3DFMT_D15S1:
2124 case WINED3DFMT_D24X8:
2125 case WINED3DFMT_D24X4S4:
2126 case WINED3DFMT_D24S8:
2127 case WINED3DFMT_D24FS8:
2128 case WINED3DFMT_D32:
2129 case WINED3DFMT_D32F_LOCKABLE:
2130 return FALSE;
2132 /*****
2133 * Not supported everywhere(depends on GL_ATI_envmap_bumpmap or
2134 * GL_NV_texture_shader), but advertized to make apps happy.
2135 * Enable some because games often fail when they are not available
2136 * and are still playable even without bump mapping
2138 case WINED3DFMT_V8U8:
2139 if(GL_SUPPORT(NV_TEXTURE_SHADER) || GL_SUPPORT(ATI_ENVMAP_BUMPMAP) ||
2140 GL_SUPPORT(ATI_FRAGMENT_SHADER)) {
2141 return TRUE;
2143 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2144 return FALSE;
2146 case WINED3DFMT_X8L8V8U8:
2147 case WINED3DFMT_L6V5U5:
2148 WARN_(d3d_caps)("[FAILED]\n");
2149 return FALSE;
2151 case WINED3DFMT_Q8W8V8U8:
2152 case WINED3DFMT_V16U16:
2153 if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
2154 WARN_(d3d_caps)("[Not supported, but pretended to do]\n");
2155 return TRUE;
2157 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2158 return FALSE;
2160 /* Those are not advertized by the nvidia windows driver, and not
2161 * supported natively by GL_NV_texture_shader or GL_ATI_envmap_bumpmap.
2162 * WINED3DFMT_A2W10V10U10 could be loaded into shaders using the unsigned
2163 * ARGB format if needed
2165 case WINED3DFMT_W11V11U10:
2166 case WINED3DFMT_A2W10V10U10:
2167 WARN_(d3d_caps)("[FAILED]\n");
2168 return FALSE;
2170 case WINED3DFMT_DXT1:
2171 case WINED3DFMT_DXT2:
2172 case WINED3DFMT_DXT3:
2173 case WINED3DFMT_DXT4:
2174 case WINED3DFMT_DXT5:
2175 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
2176 TRACE_(d3d_caps)("[OK]\n");
2177 return TRUE;
2179 TRACE_(d3d_caps)("[FAILED]\n");
2180 return FALSE;
2183 /*****
2184 * Odd formats - not supported
2186 case WINED3DFMT_VERTEXDATA:
2187 case WINED3DFMT_INDEX16:
2188 case WINED3DFMT_INDEX32:
2189 case WINED3DFMT_Q16W16V16U16:
2190 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2191 return FALSE;
2193 /*****
2194 * WINED3DFMT_CxV8U8: Not supported right now
2196 case WINED3DFMT_CxV8U8:
2197 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2198 return FALSE;
2200 /* YUV formats, not supported for now */
2201 case WINED3DFMT_UYVY:
2202 case WINED3DFMT_YUY2:
2203 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2204 return FALSE;
2206 /* Not supported */
2207 case WINED3DFMT_A16B16G16R16:
2208 case WINED3DFMT_A8R3G3B2:
2209 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2210 return FALSE;
2212 /* Floating point formats */
2213 case WINED3DFMT_R16F:
2214 case WINED3DFMT_A16B16G16R16F:
2215 if(GL_SUPPORT(ARB_HALF_FLOAT_PIXEL)) {
2216 TRACE_(d3d_caps)("[OK]\n");
2217 return TRUE;
2219 TRACE_(d3d_caps)("[FAILED]\n");
2220 return FALSE;
2222 case WINED3DFMT_R32F:
2223 case WINED3DFMT_A32B32G32R32F:
2224 if (GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2225 TRACE_(d3d_caps)("[OK]\n");
2226 return TRUE;
2228 TRACE_(d3d_caps)("[FAILED]\n");
2229 return FALSE;
2231 case WINED3DFMT_G16R16F:
2232 case WINED3DFMT_G32R32F:
2233 TRACE_(d3d_caps)("[FAILED]\n");
2234 return FALSE;
2236 /* ATI instancing hack: Although ATI cards do not support Shader Model 3.0, they support
2237 * instancing. To query if the card supports instancing CheckDeviceFormat with the special format
2238 * MAKEFOURCC('I','N','S','T') is used. Should a (broken) app check for this provide a proper return value.
2239 * We can do instancing with all shader versions, but we need vertex shaders.
2241 * Additionally applications have to set the D3DRS_POINTSIZE render state to MAKEFOURCC('I','N','S','T') once
2242 * to enable instancing. WineD3D doesn't need that and just ignores it.
2244 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows.
2246 case WINEMAKEFOURCC('I','N','S','T'):
2247 TRACE("ATI Instancing check hack\n");
2248 if(GL_SUPPORT(ARB_VERTEX_PROGRAM) || GL_SUPPORT(ARB_VERTEX_SHADER)) {
2249 TRACE_(d3d_caps)("[OK]\n");
2250 return TRUE;
2252 TRACE_(d3d_caps)("[FAILED]\n");
2253 return FALSE;
2255 /* Some weird FOURCC formats */
2256 case WINED3DFMT_R8G8_B8G8:
2257 case WINED3DFMT_G8R8_G8B8:
2258 case WINED3DFMT_MULTI2_ARGB8:
2259 TRACE_(d3d_caps)("[FAILED]\n");
2260 return FALSE;
2262 case WINED3DFMT_UNKNOWN:
2263 return FALSE;
2265 default:
2266 ERR("Unhandled format=%s\n", debug_d3dformat(CheckFormat));
2267 break;
2269 return FALSE;
2272 static BOOL CheckVertexTextureCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2274 if (!GL_LIMITS(vertex_samplers)) {
2275 TRACE_(d3d_caps)("[FAILED]\n");
2276 return FALSE;
2279 switch (CheckFormat) {
2280 case WINED3DFMT_A32B32G32R32F:
2281 if (!GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2282 TRACE_(d3d_caps)("[FAILED]\n");
2283 return FALSE;
2285 TRACE_(d3d_caps)("[OK]\n");
2286 return TRUE;
2288 default:
2289 TRACE_(d3d_caps)("[FAILED]\n");
2290 return FALSE;
2292 return FALSE;
2295 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2296 WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat) {
2297 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2298 DWORD UsageCaps = 0;
2300 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%u,%s,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s))\n",
2301 This,
2302 Adapter,
2303 DeviceType, debug_d3ddevicetype(DeviceType),
2304 AdapterFormat, debug_d3dformat(AdapterFormat),
2305 Usage, debug_d3dusage(Usage), debug_d3dusagequery(Usage),
2306 RType, debug_d3dresourcetype(RType),
2307 CheckFormat, debug_d3dformat(CheckFormat));
2309 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2310 return WINED3DERR_INVALIDCALL;
2313 if(RType == WINED3DRTYPE_CUBETEXTURE) {
2314 /* Cubetexture allows:
2315 * - D3DUSAGE_AUTOGENMIPMAP
2316 * - D3DUSAGE_DEPTHSTENCIL
2317 * - D3DUSAGE_DYNAMIC
2318 * - D3DUSAGE_NONSECURE (d3d9ex)
2319 * - D3DUSAGE_RENDERTARGET
2320 * - D3DUSAGE_SOFTWAREPROCESSING
2322 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2323 /* Check if the texture format is around */
2324 if(CheckTextureCapability(Adapter, CheckFormat)) {
2325 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
2326 /* Check for automatic mipmap generation support */
2327 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2328 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
2329 } else {
2330 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUOTGEN instead of D3D_OK */
2331 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
2335 /* Always report dynamic locking */
2336 if(Usage & WINED3DUSAGE_DYNAMIC)
2337 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2339 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2340 if(CheckRenderTargetCapability(AdapterFormat, CheckFormat)) {
2341 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2342 } else {
2343 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2344 return WINED3DERR_NOTAVAILABLE;
2348 /* Always report software processing */
2349 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2350 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2352 /* Check QUERY_FILTER support */
2353 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2354 if(CheckFilterCapability(CheckFormat)) {
2355 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2356 } else {
2357 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2358 return WINED3DERR_NOTAVAILABLE;
2362 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2363 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2364 if(CheckPostPixelShaderBlendingCapability(Adapter, CheckFormat)) {
2365 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2366 } else {
2367 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2368 return WINED3DERR_NOTAVAILABLE;
2372 /* Check QUERY_SRGBREAD support */
2373 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2374 if(CheckSrgbReadCapability(Adapter, CheckFormat)) {
2375 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2376 } else {
2377 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2378 return WINED3DERR_NOTAVAILABLE;
2382 /* Check QUERY_SRGBWRITE support */
2383 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2384 if(CheckSrgbWriteCapability(Adapter, DeviceType, CheckFormat)) {
2385 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2386 } else {
2387 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2388 return WINED3DERR_NOTAVAILABLE;
2392 /* Check QUERY_VERTEXTEXTURE support */
2393 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2394 if(CheckVertexTextureCapability(Adapter, CheckFormat)) {
2395 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2396 } else {
2397 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2398 return WINED3DERR_NOTAVAILABLE;
2401 } else {
2402 TRACE_(d3d_caps)("[FAILED] - Cube texture format not supported\n");
2403 return WINED3DERR_NOTAVAILABLE;
2405 } else {
2406 TRACE_(d3d_caps)("[FAILED] - No cube texture support\n");
2407 return WINED3DERR_NOTAVAILABLE;
2409 } else if(RType == WINED3DRTYPE_SURFACE) {
2410 /* Surface allows:
2411 * - D3DUSAGE_DEPTHSTENCIL
2412 * - D3DUSAGE_NONSECURE (d3d9ex)
2413 * - D3DUSAGE_RENDERTARGET
2416 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
2417 if(CheckDepthStencilCapability(Adapter, AdapterFormat, CheckFormat)) {
2418 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
2419 } else {
2420 TRACE_(d3d_caps)("[FAILED] - No depthstencil support\n");
2421 return WINED3DERR_NOTAVAILABLE;
2425 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2426 if(CheckRenderTargetCapability(AdapterFormat, CheckFormat)) {
2427 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2428 } else {
2429 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2430 return WINED3DERR_NOTAVAILABLE;
2433 } else if(RType == WINED3DRTYPE_TEXTURE) {
2434 /* Texture allows:
2435 * - D3DUSAGE_AUTOGENMIPMAP
2436 * - D3DUSAGE_DEPTHSTENCIL
2437 * - D3DUSAGE_DMAP
2438 * - D3DUSAGE_DYNAMIC
2439 * - D3DUSAGE_NONSECURE (d3d9ex)
2440 * - D3DUSAGE_RENDERTARGET
2441 * - D3DUSAGE_SOFTWAREPROCESSING
2442 * - D3DUSAGE_TEXTAPI (d3d9ex)
2445 /* Check if the texture format is around */
2446 if(CheckTextureCapability(Adapter, CheckFormat)) {
2447 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
2448 /* Check for automatic mipmap generation support */
2449 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2450 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
2451 } else {
2452 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUOTGEN instead of D3D_OK */
2453 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
2457 /* Always report dynamic locking */
2458 if(Usage & WINED3DUSAGE_DYNAMIC)
2459 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2461 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2462 if(CheckRenderTargetCapability(AdapterFormat, CheckFormat)) {
2463 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2464 } else {
2465 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2466 return WINED3DERR_NOTAVAILABLE;
2470 /* Always report software processing */
2471 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2472 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2474 /* Check QUERY_FILTER support */
2475 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2476 if(CheckFilterCapability(CheckFormat)) {
2477 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2478 } else {
2479 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2480 return WINED3DERR_NOTAVAILABLE;
2484 /* Check QUERY_LEGACYBUMPMAP support */
2485 if(Usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP) {
2486 if(CheckBumpMapCapability(Adapter, CheckFormat)) {
2487 UsageCaps |= WINED3DUSAGE_QUERY_LEGACYBUMPMAP;
2488 } else {
2489 TRACE_(d3d_caps)("[FAILED] - No legacy bumpmap support\n");
2490 return WINED3DERR_NOTAVAILABLE;
2494 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2495 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2496 if(CheckPostPixelShaderBlendingCapability(Adapter, CheckFormat)) {
2497 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2498 } else {
2499 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2500 return WINED3DERR_NOTAVAILABLE;
2504 /* Check QUERY_SRGBREAD support */
2505 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2506 if(CheckSrgbReadCapability(Adapter, CheckFormat)) {
2507 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2508 } else {
2509 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2510 return WINED3DERR_NOTAVAILABLE;
2514 /* Check QUERY_SRGBWRITE support */
2515 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2516 if(CheckSrgbWriteCapability(Adapter, DeviceType, CheckFormat)) {
2517 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2518 } else {
2519 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2520 return WINED3DERR_NOTAVAILABLE;
2524 /* Check QUERY_VERTEXTEXTURE support */
2525 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2526 if(CheckVertexTextureCapability(Adapter, CheckFormat)) {
2527 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2528 } else {
2529 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2530 return WINED3DERR_NOTAVAILABLE;
2533 } else if(CheckDepthStencilCapability(Adapter, AdapterFormat, CheckFormat)) {
2534 if(Usage & WINED3DUSAGE_DEPTHSTENCIL)
2535 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
2536 } else {
2537 TRACE_(d3d_caps)("[FAILED] - Texture format not supported\n");
2538 return WINED3DERR_NOTAVAILABLE;
2540 } else if((RType == WINED3DRTYPE_VOLUME) || (RType == WINED3DRTYPE_VOLUMETEXTURE)) {
2541 /* Volume is to VolumeTexture what Surface is to Texture but its usage caps are not documented.
2542 * Most driver seem to offer (nearly) the same on Volume and VolumeTexture, so do that too.
2544 * Volumetexture allows:
2545 * - D3DUSAGE_DYNAMIC
2546 * - D3DUSAGE_NONSECURE (d3d9ex)
2547 * - D3DUSAGE_SOFTWAREPROCESSING
2550 /* Check volume texture and volume usage caps */
2551 if(GL_SUPPORT(EXT_TEXTURE3D)) {
2552 if(CheckTextureCapability(Adapter, CheckFormat) == FALSE) {
2553 TRACE_(d3d_caps)("[FAILED] - Format not supported\n");
2554 return WINED3DERR_NOTAVAILABLE;
2557 /* Always report dynamic locking */
2558 if(Usage & WINED3DUSAGE_DYNAMIC)
2559 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2561 /* Always report software processing */
2562 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2563 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2565 /* Check QUERY_FILTER support */
2566 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2567 if(CheckFilterCapability(CheckFormat)) {
2568 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2569 } else {
2570 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2571 return WINED3DERR_NOTAVAILABLE;
2575 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
2576 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
2577 if(CheckPostPixelShaderBlendingCapability(Adapter, CheckFormat)) {
2578 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
2579 } else {
2580 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
2581 return WINED3DERR_NOTAVAILABLE;
2585 /* Check QUERY_SRGBREAD support */
2586 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2587 if(CheckSrgbReadCapability(Adapter, CheckFormat)) {
2588 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2589 } else {
2590 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2591 return WINED3DERR_NOTAVAILABLE;
2595 /* Check QUERY_SRGBWRITE support */
2596 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2597 if(CheckSrgbWriteCapability(Adapter, DeviceType, CheckFormat)) {
2598 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2599 } else {
2600 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2601 return WINED3DERR_NOTAVAILABLE;
2605 /* Check QUERY_VERTEXTEXTURE support */
2606 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2607 if(CheckVertexTextureCapability(Adapter, CheckFormat)) {
2608 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2609 } else {
2610 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2611 return WINED3DERR_NOTAVAILABLE;
2614 } else {
2615 TRACE_(d3d_caps)("[FAILED] - No volume texture support\n");
2616 return WINED3DERR_NOTAVAILABLE;
2619 /* Filter formats that need conversion; For one part, this conversion is unimplemented,
2620 * and volume textures are huge, so it would be a big performance hit. Unless we hit an
2621 * app needing one of those formats, don't advertize them to avoid leading apps into
2622 * temptation. The windows drivers don't support most of those formats on volumes anyway,
2623 * except of R32F.
2625 switch(CheckFormat) {
2626 case WINED3DFMT_P8:
2627 case WINED3DFMT_A4L4:
2628 case WINED3DFMT_R32F:
2629 case WINED3DFMT_R16F:
2630 case WINED3DFMT_X8L8V8U8:
2631 case WINED3DFMT_L6V5U5:
2632 case WINED3DFMT_G16R16:
2633 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2634 return WINED3DERR_NOTAVAILABLE;
2636 case WINED3DFMT_Q8W8V8U8:
2637 case WINED3DFMT_V16U16:
2638 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
2639 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2640 return WINED3DERR_NOTAVAILABLE;
2642 break;
2644 case WINED3DFMT_V8U8:
2645 if(!GL_SUPPORT(NV_TEXTURE_SHADER) || !GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
2646 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2647 return WINED3DERR_NOTAVAILABLE;
2649 break;
2651 case WINED3DFMT_DXT1:
2652 case WINED3DFMT_DXT2:
2653 case WINED3DFMT_DXT3:
2654 case WINED3DFMT_DXT4:
2655 case WINED3DFMT_DXT5:
2656 /* The GL_EXT_texture_compression_s3tc spec requires that loading an s3tc
2657 * compressed texture results in an error. While the D3D refrast does
2658 * support s3tc volumes, at least the nvidia windows driver does not, so
2659 * we're free not to support this format.
2661 TRACE_(d3d_caps)("[FAILED] - DXTn does not support 3D textures\n");
2662 return WINED3DERR_NOTAVAILABLE;
2664 default:
2665 /* Do nothing, continue with checking the format below */
2666 break;
2668 } else if((RType == WINED3DRTYPE_INDEXBUFFER) || (RType == WINED3DRTYPE_VERTEXBUFFER)){
2669 /* For instance vertexbuffer/indexbuffer aren't supported yet because no Windows drivers seem to offer it */
2670 TRACE_(d3d_caps)("Unhandled resource type D3DRTYPE_INDEXBUFFER / D3DRTYPE_VERTEXBUFFER\n");
2671 return WINED3DERR_NOTAVAILABLE;
2674 /* This format is nothing special and it is supported perfectly.
2675 * However, ati and nvidia driver on windows do not mark this format as
2676 * supported (tested with the dxCapsViewer) and pretending to
2677 * support this format uncovers a bug in Battlefield 1942 (fonts are missing)
2678 * So do the same as Windows drivers and pretend not to support it on dx8 and 9
2679 * Enable it on dx7. It will need additional checking on dx10 when we support it.
2681 if(This->dxVersion > 7 && CheckFormat == WINED3DFMT_R8G8B8) {
2682 TRACE_(d3d_caps)("[FAILED]\n");
2683 return WINED3DERR_NOTAVAILABLE;
2686 /* When the UsageCaps exactly matches Usage return WINED3D_OK except for the situation in which
2687 * WINED3DUSAGE_AUTOGENMIPMAP isn't around, then WINED3DOK_NOAUTOGEN is returned if all the other
2688 * usage flags match. */
2689 if(UsageCaps == Usage) {
2690 return WINED3D_OK;
2691 } else if((UsageCaps == (Usage & ~WINED3DUSAGE_AUTOGENMIPMAP)) && (Usage & WINED3DUSAGE_AUTOGENMIPMAP)){
2692 return WINED3DOK_NOAUTOGEN;
2693 } else {
2694 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);
2695 return WINED3DERR_NOTAVAILABLE;
2699 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2700 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
2701 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2703 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))\n",
2704 This,
2705 Adapter,
2706 DeviceType, debug_d3ddevicetype(DeviceType),
2707 SourceFormat, debug_d3dformat(SourceFormat),
2708 TargetFormat, debug_d3dformat(TargetFormat));
2709 return WINED3D_OK;
2712 static const shader_backend_t *select_shader_backend(UINT Adapter, WINED3DDEVTYPE DeviceType) {
2713 const shader_backend_t *ret;
2714 int vs_selected_mode;
2715 int ps_selected_mode;
2717 select_shader_mode(&GLINFO_LOCATION, DeviceType, &ps_selected_mode, &vs_selected_mode);
2718 if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) {
2719 ret = &glsl_shader_backend;
2720 } else if (vs_selected_mode == SHADER_ARB && ps_selected_mode != SHADER_NONE &&
2721 !GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
2722 ret = &atifs_shader_backend;
2723 } else if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) {
2724 ret = &arb_program_shader_backend;
2725 } else {
2726 ret = &none_shader_backend;
2728 return ret;
2731 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
2732 subset of a D3DCAPS9 structure. However, it has to come via a void *
2733 as the d3d8 interface cannot import the d3d9 header */
2734 static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
2736 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2737 int vs_selected_mode;
2738 int ps_selected_mode;
2739 struct shader_caps shader_caps;
2740 const shader_backend_t *shader_backend;
2742 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
2744 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2745 return WINED3DERR_INVALIDCALL;
2748 select_shader_mode(&Adapters[Adapter].gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
2750 /* This function should *not* be modifying GL caps
2751 * TODO: move the functionality where it belongs */
2752 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &Adapters[Adapter].gl_info);
2754 /* ------------------------------------------------
2755 The following fields apply to both d3d8 and d3d9
2756 ------------------------------------------------ */
2757 pCaps->DeviceType = (DeviceType == WINED3DDEVTYPE_HAL) ? WINED3DDEVTYPE_HAL : WINED3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
2758 pCaps->AdapterOrdinal = Adapter;
2760 pCaps->Caps = 0;
2761 pCaps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
2762 WINED3DCAPS2_FULLSCREENGAMMA |
2763 WINED3DCAPS2_DYNAMICTEXTURES;
2764 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2765 pCaps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
2767 pCaps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD;
2768 pCaps->PresentationIntervals = WINED3DPRESENT_INTERVAL_IMMEDIATE |
2769 WINED3DPRESENT_INTERVAL_ONE;
2771 pCaps->CursorCaps = WINED3DCURSORCAPS_COLOR |
2772 WINED3DCURSORCAPS_LOWRES;
2774 pCaps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
2775 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
2776 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
2777 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
2778 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
2779 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
2780 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
2781 WINED3DDEVCAPS_PUREDEVICE |
2782 WINED3DDEVCAPS_HWRASTERIZATION |
2783 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
2784 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
2785 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
2786 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
2787 WINED3DDEVCAPS_DRAWPRIMITIVES2EX |
2788 WINED3DDEVCAPS_RTPATCHES;
2790 pCaps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
2791 WINED3DPMISCCAPS_CULLCCW |
2792 WINED3DPMISCCAPS_CULLCW |
2793 WINED3DPMISCCAPS_COLORWRITEENABLE |
2794 WINED3DPMISCCAPS_CLIPTLVERTS |
2795 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
2796 WINED3DPMISCCAPS_MASKZ |
2797 WINED3DPMISCCAPS_BLENDOP;
2798 /* TODO:
2799 WINED3DPMISCCAPS_NULLREFERENCE
2800 WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS
2801 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
2802 WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
2803 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING
2804 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
2806 if(GL_SUPPORT(EXT_BLEND_EQUATION_SEPARATE) && GL_SUPPORT(EXT_BLEND_FUNC_SEPARATE))
2807 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
2809 /* The caps below can be supported but aren't handled yet in utils.c 'd3dta_to_combiner_input', disable them until support is fixed */
2810 #if 0
2811 if (GL_SUPPORT(NV_REGISTER_COMBINERS))
2812 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_TSSARGTEMP;
2813 if (GL_SUPPORT(NV_REGISTER_COMBINERS2))
2814 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_PERSTAGECONSTANT;
2815 #endif
2817 pCaps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
2818 WINED3DPRASTERCAPS_PAT |
2819 WINED3DPRASTERCAPS_WFOG |
2820 WINED3DPRASTERCAPS_ZFOG |
2821 WINED3DPRASTERCAPS_FOGVERTEX |
2822 WINED3DPRASTERCAPS_FOGTABLE |
2823 WINED3DPRASTERCAPS_STIPPLE |
2824 WINED3DPRASTERCAPS_SUBPIXEL |
2825 WINED3DPRASTERCAPS_ZTEST |
2826 WINED3DPRASTERCAPS_SCISSORTEST |
2827 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
2828 WINED3DPRASTERCAPS_DEPTHBIAS;
2830 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2831 pCaps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY |
2832 WINED3DPRASTERCAPS_ZBIAS |
2833 WINED3DPRASTERCAPS_MIPMAPLODBIAS;
2835 if(GL_SUPPORT(NV_FOG_DISTANCE)) {
2836 pCaps->RasterCaps |= WINED3DPRASTERCAPS_FOGRANGE;
2838 /* FIXME Add:
2839 WINED3DPRASTERCAPS_COLORPERSPECTIVE
2840 WINED3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
2841 WINED3DPRASTERCAPS_ANTIALIASEDGES
2842 WINED3DPRASTERCAPS_ZBUFFERLESSHSR
2843 WINED3DPRASTERCAPS_WBUFFER */
2845 pCaps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
2846 WINED3DPCMPCAPS_EQUAL |
2847 WINED3DPCMPCAPS_GREATER |
2848 WINED3DPCMPCAPS_GREATEREQUAL |
2849 WINED3DPCMPCAPS_LESS |
2850 WINED3DPCMPCAPS_LESSEQUAL |
2851 WINED3DPCMPCAPS_NEVER |
2852 WINED3DPCMPCAPS_NOTEQUAL;
2854 pCaps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
2855 WINED3DPBLENDCAPS_BOTHSRCALPHA |
2856 WINED3DPBLENDCAPS_DESTALPHA |
2857 WINED3DPBLENDCAPS_DESTCOLOR |
2858 WINED3DPBLENDCAPS_INVDESTALPHA |
2859 WINED3DPBLENDCAPS_INVDESTCOLOR |
2860 WINED3DPBLENDCAPS_INVSRCALPHA |
2861 WINED3DPBLENDCAPS_INVSRCCOLOR |
2862 WINED3DPBLENDCAPS_ONE |
2863 WINED3DPBLENDCAPS_SRCALPHA |
2864 WINED3DPBLENDCAPS_SRCALPHASAT |
2865 WINED3DPBLENDCAPS_SRCCOLOR |
2866 WINED3DPBLENDCAPS_ZERO;
2868 pCaps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
2869 WINED3DPBLENDCAPS_DESTCOLOR |
2870 WINED3DPBLENDCAPS_INVDESTALPHA |
2871 WINED3DPBLENDCAPS_INVDESTCOLOR |
2872 WINED3DPBLENDCAPS_INVSRCALPHA |
2873 WINED3DPBLENDCAPS_INVSRCCOLOR |
2874 WINED3DPBLENDCAPS_ONE |
2875 WINED3DPBLENDCAPS_SRCALPHA |
2876 WINED3DPBLENDCAPS_SRCCOLOR |
2877 WINED3DPBLENDCAPS_ZERO;
2878 /* NOTE: WINED3DPBLENDCAPS_SRCALPHASAT is not supported as dest blend factor,
2879 * according to the glBlendFunc manpage
2881 * WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA are
2882 * legacy settings for srcblend only
2885 if( GL_SUPPORT(EXT_BLEND_COLOR)) {
2886 pCaps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
2887 pCaps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
2891 pCaps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
2892 WINED3DPCMPCAPS_EQUAL |
2893 WINED3DPCMPCAPS_GREATER |
2894 WINED3DPCMPCAPS_GREATEREQUAL |
2895 WINED3DPCMPCAPS_LESS |
2896 WINED3DPCMPCAPS_LESSEQUAL |
2897 WINED3DPCMPCAPS_NEVER |
2898 WINED3DPCMPCAPS_NOTEQUAL;
2900 pCaps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
2901 WINED3DPSHADECAPS_COLORGOURAUDRGB |
2902 WINED3DPSHADECAPS_ALPHAFLATBLEND |
2903 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
2904 WINED3DPSHADECAPS_COLORFLATRGB |
2905 WINED3DPSHADECAPS_FOGFLAT |
2906 WINED3DPSHADECAPS_FOGGOURAUD |
2907 WINED3DPSHADECAPS_SPECULARFLATRGB;
2909 pCaps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
2910 WINED3DPTEXTURECAPS_ALPHAPALETTE |
2911 WINED3DPTEXTURECAPS_BORDER |
2912 WINED3DPTEXTURECAPS_MIPMAP |
2913 WINED3DPTEXTURECAPS_PROJECTED |
2914 WINED3DPTEXTURECAPS_PERSPECTIVE;
2916 if( !GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
2917 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
2918 WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
2921 if( GL_SUPPORT(EXT_TEXTURE3D)) {
2922 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP |
2923 WINED3DPTEXTURECAPS_MIPVOLUMEMAP |
2924 WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
2927 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2928 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP |
2929 WINED3DPTEXTURECAPS_MIPCUBEMAP |
2930 WINED3DPTEXTURECAPS_CUBEMAP_POW2;
2934 pCaps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2935 WINED3DPTFILTERCAPS_MAGFPOINT |
2936 WINED3DPTFILTERCAPS_MINFLINEAR |
2937 WINED3DPTFILTERCAPS_MINFPOINT |
2938 WINED3DPTFILTERCAPS_MIPFLINEAR |
2939 WINED3DPTFILTERCAPS_MIPFPOINT |
2940 WINED3DPTFILTERCAPS_LINEAR |
2941 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2942 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2943 WINED3DPTFILTERCAPS_MIPLINEAR |
2944 WINED3DPTFILTERCAPS_MIPNEAREST |
2945 WINED3DPTFILTERCAPS_NEAREST;
2947 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2948 pCaps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
2949 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
2952 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2953 pCaps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2954 WINED3DPTFILTERCAPS_MAGFPOINT |
2955 WINED3DPTFILTERCAPS_MINFLINEAR |
2956 WINED3DPTFILTERCAPS_MINFPOINT |
2957 WINED3DPTFILTERCAPS_MIPFLINEAR |
2958 WINED3DPTFILTERCAPS_MIPFPOINT |
2959 WINED3DPTFILTERCAPS_LINEAR |
2960 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2961 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2962 WINED3DPTFILTERCAPS_MIPLINEAR |
2963 WINED3DPTFILTERCAPS_MIPNEAREST |
2964 WINED3DPTFILTERCAPS_NEAREST;
2966 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2967 pCaps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
2968 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
2970 } else
2971 pCaps->CubeTextureFilterCaps = 0;
2973 if (GL_SUPPORT(EXT_TEXTURE3D)) {
2974 pCaps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2975 WINED3DPTFILTERCAPS_MAGFPOINT |
2976 WINED3DPTFILTERCAPS_MINFLINEAR |
2977 WINED3DPTFILTERCAPS_MINFPOINT |
2978 WINED3DPTFILTERCAPS_MIPFLINEAR |
2979 WINED3DPTFILTERCAPS_MIPFPOINT |
2980 WINED3DPTFILTERCAPS_LINEAR |
2981 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2982 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2983 WINED3DPTFILTERCAPS_MIPLINEAR |
2984 WINED3DPTFILTERCAPS_MIPNEAREST |
2985 WINED3DPTFILTERCAPS_NEAREST;
2986 } else
2987 pCaps->VolumeTextureFilterCaps = 0;
2989 pCaps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
2990 WINED3DPTADDRESSCAPS_CLAMP |
2991 WINED3DPTADDRESSCAPS_WRAP;
2993 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
2994 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
2996 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
2997 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
2999 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
3000 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
3003 if (GL_SUPPORT(EXT_TEXTURE3D)) {
3004 pCaps->VolumeTextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
3005 WINED3DPTADDRESSCAPS_CLAMP |
3006 WINED3DPTADDRESSCAPS_WRAP;
3007 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
3008 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
3010 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
3011 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
3013 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
3014 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
3016 } else
3017 pCaps->VolumeTextureAddressCaps = 0;
3019 pCaps->LineCaps = WINED3DLINECAPS_TEXTURE |
3020 WINED3DLINECAPS_ZTEST;
3021 /* FIXME: Add
3022 WINED3DLINECAPS_BLEND
3023 WINED3DLINECAPS_ALPHACMP
3024 WINED3DLINECAPS_FOG */
3026 pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
3027 pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
3029 if(GL_SUPPORT(EXT_TEXTURE3D))
3030 pCaps->MaxVolumeExtent = GL_LIMITS(texture3d_size);
3031 else
3032 pCaps->MaxVolumeExtent = 0;
3034 pCaps->MaxTextureRepeat = 32768;
3035 pCaps->MaxTextureAspectRatio = GL_LIMITS(texture_size);
3036 pCaps->MaxVertexW = 1.0;
3038 pCaps->GuardBandLeft = 0;
3039 pCaps->GuardBandTop = 0;
3040 pCaps->GuardBandRight = 0;
3041 pCaps->GuardBandBottom = 0;
3043 pCaps->ExtentsAdjust = 0;
3045 pCaps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
3046 WINED3DSTENCILCAPS_INCRSAT |
3047 WINED3DSTENCILCAPS_INVERT |
3048 WINED3DSTENCILCAPS_KEEP |
3049 WINED3DSTENCILCAPS_REPLACE |
3050 WINED3DSTENCILCAPS_ZERO;
3051 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
3052 pCaps->StencilCaps |= WINED3DSTENCILCAPS_DECR |
3053 WINED3DSTENCILCAPS_INCR;
3055 if ( This->dxVersion > 8 &&
3056 ( GL_SUPPORT(EXT_STENCIL_TWO_SIDE) ||
3057 GL_SUPPORT(ATI_SEPARATE_STENCIL) ) ) {
3058 pCaps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
3061 pCaps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
3063 pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
3064 pCaps->MaxActiveLights = GL_LIMITS(lights);
3066 pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
3067 pCaps->MaxVertexBlendMatrixIndex = 0;
3069 pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
3070 pCaps->MaxPointSize = GL_LIMITS(pointsize);
3073 pCaps->VertexProcessingCaps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
3074 WINED3DVTXPCAPS_MATERIALSOURCE7 |
3075 WINED3DVTXPCAPS_POSITIONALLIGHTS |
3076 WINED3DVTXPCAPS_LOCALVIEWER |
3077 WINED3DVTXPCAPS_VERTEXFOG |
3078 WINED3DVTXPCAPS_TEXGEN;
3079 /* FIXME: Add
3080 D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
3082 pCaps->MaxPrimitiveCount = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
3083 pCaps->MaxVertexIndex = 0xFFFFF;
3084 pCaps->MaxStreams = MAX_STREAMS;
3085 pCaps->MaxStreamStride = 1024;
3087 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
3088 pCaps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET;
3089 /* TODO: VS3.0 needs at least D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET */
3090 pCaps->MaxNpatchTessellationLevel = 0;
3091 pCaps->MasterAdapterOrdinal = 0;
3092 pCaps->AdapterOrdinalInGroup = 0;
3093 pCaps->NumberOfAdaptersInGroup = 1;
3095 pCaps->NumSimultaneousRTs = GL_LIMITS(buffers);
3097 pCaps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
3098 WINED3DPTFILTERCAPS_MAGFPOINT |
3099 WINED3DPTFILTERCAPS_MINFLINEAR |
3100 WINED3DPTFILTERCAPS_MAGFLINEAR;
3101 pCaps->VertexTextureFilterCaps = 0;
3103 memset(&shader_caps, 0, sizeof(shader_caps));
3104 shader_backend = select_shader_backend(Adapter, DeviceType);
3105 shader_backend->shader_get_caps(DeviceType, &GLINFO_LOCATION, &shader_caps);
3107 /* This takes care for disabling vertex shader or pixel shader caps while leaving the other one enabled.
3108 * Ignore shader model capabilities if disabled in config
3110 if(vs_selected_mode == SHADER_NONE) {
3111 TRACE_(d3d_caps)("Vertex shader disabled in config, reporting version 0.0\n");
3112 pCaps->VertexShaderVersion = WINED3DVS_VERSION(0,0);
3113 pCaps->MaxVertexShaderConst = 0;
3114 } else {
3115 pCaps->VertexShaderVersion = shader_caps.VertexShaderVersion;
3116 pCaps->MaxVertexShaderConst = shader_caps.MaxVertexShaderConst;
3119 if(ps_selected_mode == SHADER_NONE) {
3120 TRACE_(d3d_caps)("Pixel shader disabled in config, reporting version 0.0\n");
3121 pCaps->PixelShaderVersion = WINED3DPS_VERSION(0,0);
3122 pCaps->PixelShader1xMaxValue = 0.0;
3123 } else {
3124 pCaps->PixelShaderVersion = shader_caps.PixelShaderVersion;
3125 pCaps->PixelShader1xMaxValue = shader_caps.PixelShader1xMaxValue;
3128 pCaps->TextureOpCaps = shader_caps.TextureOpCaps;
3129 pCaps->MaxTextureBlendStages = shader_caps.MaxTextureBlendStages;
3130 pCaps->MaxSimultaneousTextures = shader_caps.MaxSimultaneousTextures;
3131 pCaps->VS20Caps = shader_caps.VS20Caps;
3132 pCaps->MaxVShaderInstructionsExecuted = shader_caps.MaxVShaderInstructionsExecuted;
3133 pCaps->MaxVertexShader30InstructionSlots= shader_caps.MaxVertexShader30InstructionSlots;
3134 pCaps->PS20Caps = shader_caps.PS20Caps;
3135 pCaps->MaxPShaderInstructionsExecuted = shader_caps.MaxPShaderInstructionsExecuted;
3136 pCaps->MaxPixelShader30InstructionSlots = shader_caps.MaxPixelShader30InstructionSlots;
3138 /* The following caps are shader specific, but they are things we cannot detect, or which
3139 * are the same among all shader models. So to avoid code duplication set the shader version
3140 * specific, but otherwise constant caps here
3142 if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(3,0)) {
3143 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
3144 use the VS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum VS3.0 value. */
3145 pCaps->VS20Caps.Caps = WINED3DVS20CAPS_PREDICATION;
3146 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
3147 pCaps->VS20Caps.NumTemps = max(32, GLINFO_LOCATION.vs_arb_max_temps);
3148 pCaps->VS20Caps.StaticFlowControlDepth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH ; /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
3150 pCaps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
3151 pCaps->MaxVertexShader30InstructionSlots = max(512, GLINFO_LOCATION.vs_arb_max_instructions);
3152 } else if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(2,0)) {
3153 pCaps->VS20Caps.Caps = 0;
3154 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
3155 pCaps->VS20Caps.NumTemps = max(12, GLINFO_LOCATION.vs_arb_max_temps);
3156 pCaps->VS20Caps.StaticFlowControlDepth = 1;
3158 pCaps->MaxVShaderInstructionsExecuted = 65535;
3159 pCaps->MaxVertexShader30InstructionSlots = 0;
3160 } else { /* VS 1.x */
3161 pCaps->VS20Caps.Caps = 0;
3162 pCaps->VS20Caps.DynamicFlowControlDepth = 0;
3163 pCaps->VS20Caps.NumTemps = 0;
3164 pCaps->VS20Caps.StaticFlowControlDepth = 0;
3166 pCaps->MaxVShaderInstructionsExecuted = 0;
3167 pCaps->MaxVertexShader30InstructionSlots = 0;
3170 if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(3,0)) {
3171 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
3172 use the PS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum PS 3.0 value. */
3174 /* 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 */
3175 pCaps->PS20Caps.Caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
3176 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
3177 WINED3DPS20CAPS_PREDICATION |
3178 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
3179 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
3180 pCaps->PS20Caps.DynamicFlowControlDepth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
3181 pCaps->PS20Caps.NumTemps = max(32, GLINFO_LOCATION.ps_arb_max_temps);
3182 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
3183 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
3185 pCaps->MaxPShaderInstructionsExecuted = 65535;
3186 pCaps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS, GLINFO_LOCATION.ps_arb_max_instructions);
3187 } else if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(2,0)) {
3188 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
3189 pCaps->PS20Caps.Caps = 0;
3190 pCaps->PS20Caps.DynamicFlowControlDepth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
3191 pCaps->PS20Caps.NumTemps = max(12, GLINFO_LOCATION.ps_arb_max_temps);
3192 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
3193 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
3195 pCaps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
3196 pCaps->MaxPixelShader30InstructionSlots = 0;
3197 } else { /* PS 1.x */
3198 pCaps->PS20Caps.Caps = 0;
3199 pCaps->PS20Caps.DynamicFlowControlDepth = 0;
3200 pCaps->PS20Caps.NumTemps = 0;
3201 pCaps->PS20Caps.StaticFlowControlDepth = 0;
3202 pCaps->PS20Caps.NumInstructionSlots = 0;
3204 pCaps->MaxPShaderInstructionsExecuted = 0;
3205 pCaps->MaxPixelShader30InstructionSlots = 0;
3208 if(pCaps->VertexShaderVersion >= WINED3DVS_VERSION(2,0)) {
3209 /* OpenGL supports all the formats below, perhaps not always
3210 * without conversion, but it supports them.
3211 * Further GLSL doesn't seem to have an official unsigned type so
3212 * don't advertise it yet as I'm not sure how we handle it.
3213 * We might need to add some clamping in the shader engine to
3214 * support it.
3215 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
3216 pCaps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
3217 WINED3DDTCAPS_UBYTE4N |
3218 WINED3DDTCAPS_SHORT2N |
3219 WINED3DDTCAPS_SHORT4N;
3220 if (GL_SUPPORT(NV_HALF_FLOAT)) {
3221 pCaps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
3222 WINED3DDTCAPS_FLOAT16_4;
3224 } else
3225 pCaps->DeclTypes = 0;
3227 return WINED3D_OK;
3230 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
3231 and fields being inserted in the middle, a new structure is used in place */
3232 static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, HWND hFocusWindow,
3233 DWORD BehaviourFlags, IWineD3DDevice** ppReturnedDeviceInterface,
3234 IUnknown *parent) {
3236 IWineD3DDeviceImpl *object = NULL;
3237 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3238 WINED3DDISPLAYMODE mode;
3239 int i;
3241 /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
3242 * number and create a device without a 3D adapter for 2D only operation.
3244 if (IWineD3D_GetAdapterCount(iface) && Adapter >= IWineD3D_GetAdapterCount(iface)) {
3245 return WINED3DERR_INVALIDCALL;
3248 /* Create a WineD3DDevice object */
3249 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
3250 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
3251 TRACE("Created WineD3DDevice object @ %p\n", object);
3252 if (NULL == object) {
3253 return WINED3DERR_OUTOFVIDEOMEMORY;
3256 /* Set up initial COM information */
3257 object->lpVtbl = &IWineD3DDevice_Vtbl;
3258 object->ref = 1;
3259 object->wineD3D = iface;
3260 object->adapter = numAdapters ? &Adapters[Adapter] : NULL;
3261 IWineD3D_AddRef(object->wineD3D);
3262 object->parent = parent;
3263 list_init(&object->resources);
3264 list_init(&object->shaders);
3266 if(This->dxVersion == 7) {
3267 object->surface_alignment = 8;
3268 } else {
3269 object->surface_alignment = 4;
3271 object->posFixup[0] = 1.0; /* This is needed to get the x coord unmodified through a MAD */
3273 /* Set the state up as invalid until the device is fully created */
3274 object->state = WINED3DERR_DRIVERINTERNALERROR;
3276 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %x, RetDevInt: %p)\n", This, Adapter, DeviceType,
3277 hFocusWindow, BehaviourFlags, ppReturnedDeviceInterface);
3279 /* Save the creation parameters */
3280 object->createParms.AdapterOrdinal = Adapter;
3281 object->createParms.DeviceType = DeviceType;
3282 object->createParms.hFocusWindow = hFocusWindow;
3283 object->createParms.BehaviorFlags = BehaviourFlags;
3285 /* Initialize other useful values */
3286 object->adapterNo = Adapter;
3287 object->devType = DeviceType;
3289 select_shader_mode(&GLINFO_LOCATION, DeviceType, &object->ps_selected_mode, &object->vs_selected_mode);
3290 object->shader_backend = select_shader_backend(Adapter, DeviceType);
3292 /* Prefer the vtable with functions optimized for single dirtifyable objects if the shader
3293 * model can deal with that. It is essentially the same, just with adjusted
3294 * Set*ShaderConstantF implementations
3296 if(object->shader_backend->shader_dirtifyable_constants((IWineD3DDevice *) object)) {
3297 object->lpVtbl = &IWineD3DDevice_DirtyConst_Vtbl;
3300 /* set the state of the device to valid */
3301 object->state = WINED3D_OK;
3303 /* Get the initial screen setup for ddraw */
3304 IWineD3DImpl_GetAdapterDisplayMode(iface, Adapter, &mode);
3306 object->ddraw_width = mode.Width;
3307 object->ddraw_height = mode.Height;
3308 object->ddraw_format = mode.Format;
3310 for(i = 0; i < PATCHMAP_SIZE; i++) {
3311 list_init(&object->patches[i]);
3313 return WINED3D_OK;
3315 #undef GLINFO_LOCATION
3317 static HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
3318 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3319 IUnknown_AddRef(This->parent);
3320 *pParent = This->parent;
3321 return WINED3D_OK;
3324 ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface) {
3325 IUnknown* surfaceParent;
3326 TRACE("(%p) call back\n", pSurface);
3328 /* Now, release the parent, which will take care of cleaning up the surface for us */
3329 IWineD3DSurface_GetParent(pSurface, &surfaceParent);
3330 IUnknown_Release(surfaceParent);
3331 return IUnknown_Release(surfaceParent);
3334 ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pVolume) {
3335 IUnknown* volumeParent;
3336 TRACE("(%p) call back\n", pVolume);
3338 /* Now, release the parent, which will take care of cleaning up the volume for us */
3339 IWineD3DVolume_GetParent(pVolume, &volumeParent);
3340 IUnknown_Release(volumeParent);
3341 return IUnknown_Release(volumeParent);
3344 static BOOL implementation_is_apple(WineD3D_GL_Info *gl_info) {
3345 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
3346 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
3347 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
3349 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
3350 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
3351 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
3352 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
3353 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
3354 * the chance that other implementations support them is rather small since Win32 QuickTime uses
3355 * DirectDraw, not OpenGL.
3357 if(gl_info->supported[APPLE_FENCE] &&
3358 gl_info->supported[APPLE_CLIENT_STORAGE] &&
3359 gl_info->supported[APPLE_FLUSH_RENDER] &&
3360 gl_info->supported[APPLE_YCBCR_422]) {
3361 TRACE_(d3d_caps)("GL_APPLE_fence, GL_APPLE_client_storage, GL_APPLE_flush_render and GL_ycbcr_422 are supported\n");
3362 TRACE_(d3d_caps)("Activating MacOS fixups\n");
3363 return TRUE;
3364 } else {
3365 TRACE_(d3d_caps)("Apple extensions are not supported\n");
3366 TRACE_(d3d_caps)("Not activating MacOS fixups\n");
3367 return FALSE;
3371 #define GLINFO_LOCATION (*gl_info)
3372 static void test_pbo_functionality(WineD3D_GL_Info *gl_info) {
3373 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
3374 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
3375 * all the texture. This function detects this bug by its symptom and disables PBOs
3376 * if the test fails.
3378 * The test uplaods a 4x4 texture via the PBO in the "native" format GL_BGRA,
3379 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
3380 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
3381 * read back is compared to the original. If they are equal PBOs are assumed to work,
3382 * otherwise the PBO extension is disabled.
3384 GLuint texture, pbo;
3385 static const unsigned int pattern[] = {
3386 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
3387 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
3388 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
3389 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
3391 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
3393 if(!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) {
3394 /* No PBO -> No point in testing them */
3395 return;
3398 while(glGetError());
3399 glGenTextures(1, &texture);
3400 glBindTexture(GL_TEXTURE_2D, texture);
3401 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
3402 checkGLcall("Specifying the PBO test texture\n");
3404 GL_EXTCALL(glGenBuffersARB(1, &pbo));
3405 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
3406 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
3407 checkGLcall("Specifying the PBO test pbo\n");
3409 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
3410 checkGLcall("Loading the PBO test texture\n");
3412 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
3413 glFinish(); /* just to be sure */
3415 memset(check, 0, sizeof(check));
3416 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
3417 checkGLcall("Reading back the PBO test texture\n");
3419 glDeleteTextures(1, &texture);
3420 GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
3421 checkGLcall("PBO test cleanup\n");
3423 if(memcmp(check, pattern, sizeof(check)) != 0) {
3424 WARN_(d3d_caps)("PBO test failed, read back data doesn't match original\n");
3425 WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance\n");
3426 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
3427 } else {
3428 TRACE_(d3d_caps)("PBO test successful\n");
3431 #undef GLINFO_LOCATION
3433 /* Certain applications(Steam) complain if we report an outdated driver version. In general,
3434 * reporting a driver version is moot because we are not the Windows driver, and we have different
3435 * bugs, features, etc.
3437 * If a card is not found in this table, the gl driver version is reported
3439 struct driver_version_information {
3440 WORD vendor; /* reported PCI card vendor ID */
3441 WORD card; /* reported PCI card device ID */
3442 WORD hipart_hi, hipart_lo; /* driver hiword to report */
3443 WORD lopart_hi, lopart_lo; /* driver loword to report */
3446 static const struct driver_version_information driver_version_table[] = {
3447 /* Nvidia drivers. Geforce FX and newer cards are supported by the current driver */
3448 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, 7, 15, 10, 16921 },
3449 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, 7, 15, 10, 16921 },
3450 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, 7, 15, 10, 16921 },
3451 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, 7, 15, 10, 16921 },
3452 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, 7, 15, 10, 16921 },
3453 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, 7, 15, 10, 16921 },
3454 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, 7, 15, 10, 16921 },
3455 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, 7, 15, 10, 16921 },
3456 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, 7, 15, 10, 16921 },
3457 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, 7, 15, 10, 16921 },
3458 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, 7, 15, 10, 16921 },
3459 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, 7, 15, 10, 16921 },
3460 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, 7, 15, 10, 16921 },
3461 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, 7, 15, 10, 16921 },
3463 /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode */
3464 {VENDOR_ATI, CARD_ATI_RADEON_9500, 6, 14, 10, 6764 },
3465 {VENDOR_ATI, CARD_ATI_RADEON_X700, 6, 14, 10, 6764 },
3466 {VENDOR_ATI, CARD_ATI_RADEON_X1600, 6, 14, 10, 6764 },
3467 {VENDOR_ATI, CARD_ATI_RADEON_HD2300, 6, 14, 10, 6764 },
3468 {VENDOR_ATI, CARD_ATI_RADEON_HD2600, 6, 14, 10, 6764 },
3469 {VENDOR_ATI, CARD_ATI_RADEON_HD2900, 6, 14, 10, 6764 },
3471 /* TODO: Add information about legacy nvidia and ATI hardware, Intel and other cards */
3474 static void fixup_extensions(WineD3D_GL_Info *gl_info) {
3475 unsigned int i;
3476 BOOL apple = implementation_is_apple(gl_info);
3478 if(apple) {
3479 /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
3480 * used it falls back to software. While the compiler can detect if the shader uses all declared
3481 * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
3482 * using relative addressing falls back to software.
3484 * ARB vp gives the correct amount of uniforms, so use it instead of GLSL
3486 if(gl_info->vs_glsl_constantsF <= gl_info->vs_arb_constantsF) {
3487 FIXME("GLSL doesn't advertise more vertex shader uniforms than ARB. Driver fixup outdated?\n");
3488 } else {
3489 TRACE("Driver claims %u GLSL vs uniforms, replacing with %u ARB vp uniforms\n",
3490 gl_info->vs_glsl_constantsF, gl_info->vs_arb_constantsF);
3491 gl_info->vs_glsl_constantsF = gl_info->vs_arb_constantsF;
3494 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
3495 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
3496 * If real NP2 textures are used, the driver falls back to software. So remove the supported
3497 * flag for this extension
3499 if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] && gl_info->gl_vendor == VENDOR_ATI) {
3500 if(gl_info->gl_card == CARD_ATI_RADEON_X700 || gl_info->gl_card == CARD_ATI_RADEON_X1600 ||
3501 gl_info->gl_card == CARD_ATI_RADEON_9500 || gl_info->gl_card == CARD_ATI_RADEON_8500 ||
3502 gl_info->gl_card == CARD_ATI_RADEON_7200 || gl_info->gl_card == CARD_ATI_RAGE_128PRO) {
3503 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing\n");
3504 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
3505 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
3509 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
3510 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
3511 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
3512 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
3513 * according to the spec.
3515 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
3516 * makes the shader slower and eats instruction slots which should be available to the d3d app.
3518 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
3519 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
3520 * this workaround is activated on cards that do not need it, it won't break things, just affect
3521 * performance negatively.
3523 if(gl_info->gl_vendor == VENDOR_INTEL ||
3524 (gl_info->gl_vendor == VENDOR_ATI && gl_info->gl_card != CARD_ATI_RADEON_X1600)) {
3525 TRACE("Enabling vertex texture coord fixes in vertex shaders\n");
3526 gl_info->set_texcoord_w = TRUE;
3530 /* Find out if PBOs work as they are supposed to */
3531 test_pbo_functionality(gl_info);
3533 /* Fixup the driver version */
3534 for(i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++) {
3535 if(gl_info->gl_vendor == driver_version_table[i].vendor &&
3536 gl_info->gl_card == driver_version_table[i].card) {
3537 TRACE_(d3d_caps)("Found card 0x%04x, 0x%04x in driver version DB\n", gl_info->gl_vendor, gl_info->gl_card);
3539 gl_info->driver_version = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
3540 driver_version_table[i].lopart_lo);
3541 gl_info->driver_version_hipart = MAKEDWORD_VERSION(driver_version_table[i].hipart_hi,
3542 driver_version_table[i].hipart_lo);
3543 break;
3548 void invalid_func(void *data) {
3549 ERR("Invalid vertex attribute function called\n");
3550 DebugBreak();
3553 #define GLINFO_LOCATION (Adapters[0].gl_info)
3555 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
3556 * the extension detection and are used in drawStridedSlow
3558 static void position_d3dcolor(void *data) {
3559 DWORD pos = *((DWORD *) data);
3561 FIXME("Add a test for fixed function position from d3dcolor type\n");
3562 glVertex4s(D3DCOLOR_B_R(pos),
3563 D3DCOLOR_B_G(pos),
3564 D3DCOLOR_B_B(pos),
3565 D3DCOLOR_B_A(pos));
3567 static void position_float4(void *data) {
3568 GLfloat *pos = (float *) data;
3570 if (pos[3] < eps && pos[3] > -eps)
3571 glVertex3fv(pos);
3572 else {
3573 float w = 1.0 / pos[3];
3575 glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
3579 static void diffuse_d3dcolor(void *data) {
3580 DWORD diffuseColor = *((DWORD *) data);
3582 glColor4ub(D3DCOLOR_B_R(diffuseColor),
3583 D3DCOLOR_B_G(diffuseColor),
3584 D3DCOLOR_B_B(diffuseColor),
3585 D3DCOLOR_B_A(diffuseColor));
3588 static void specular_d3dcolor(void *data) {
3589 DWORD specularColor = *((DWORD *) data);
3591 GL_EXTCALL(glSecondaryColor3ubEXT)(D3DCOLOR_B_R(specularColor),
3592 D3DCOLOR_B_G(specularColor),
3593 D3DCOLOR_B_B(specularColor));
3595 static void warn_no_specular_func(void *data) {
3596 WARN("GL_EXT_secondary_color not supported\n");
3599 void fillGLAttribFuncs(WineD3D_GL_Info *gl_info) {
3600 position_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3601 position_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3602 position_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glVertex3fv;
3603 position_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) position_float4;
3604 position_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) position_d3dcolor;
3605 position_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3606 position_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3607 position_funcs[WINED3DDECLTYPE_SHORT4] = (void *) glVertex2sv;
3608 position_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3609 position_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3610 position_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3611 position_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3612 position_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3613 position_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3614 position_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3615 position_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3616 position_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3618 diffuse_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3619 diffuse_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3620 diffuse_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glColor3fv;
3621 diffuse_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) glColor4fv;
3622 diffuse_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) diffuse_d3dcolor;
3623 diffuse_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3624 diffuse_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3625 diffuse_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3626 diffuse_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) glColor4ubv;
3627 diffuse_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3628 diffuse_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) glColor4sv;
3629 diffuse_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3630 diffuse_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) glColor4usv;
3631 diffuse_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3632 diffuse_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3633 diffuse_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3634 diffuse_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3636 /* No 4 component entry points here */
3637 specular_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3638 specular_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3639 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
3640 specular_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) GL_EXTCALL(glSecondaryColor3fvEXT);
3641 } else {
3642 specular_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) warn_no_specular_func;
3644 specular_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) invalid_func;
3645 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
3646 specular_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) specular_d3dcolor;
3647 } else {
3648 specular_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) warn_no_specular_func;
3650 specular_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3651 specular_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3652 specular_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3653 specular_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3654 specular_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3655 specular_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3656 specular_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3657 specular_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3658 specular_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3659 specular_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3660 specular_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3661 specular_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3663 /* Only 3 component entry points here. Test how others behave. Float4 normals are used
3664 * by one of our tests, trying to pass it to the pixel shader, which fails on Windows.
3666 normal_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3667 normal_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3668 normal_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glNormal3fv;
3669 normal_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) glNormal3fv; /* Just ignore the 4th value */
3670 normal_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) invalid_func;
3671 normal_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3672 normal_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3673 normal_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3674 normal_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3675 normal_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3676 normal_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3677 normal_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3678 normal_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3679 normal_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3680 normal_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3681 normal_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3682 normal_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3685 #define PUSH1(att) attribs[nAttribs++] = (att);
3686 BOOL InitAdapters(void) {
3687 static HMODULE mod_gl;
3688 BOOL ret;
3689 int ps_selected_mode, vs_selected_mode;
3691 /* No need to hold any lock. The calling library makes sure only one thread calls
3692 * wined3d simultaneously
3694 if(numAdapters > 0) return TRUE;
3696 TRACE("Initializing adapters\n");
3698 if(!mod_gl) {
3699 #ifdef USE_WIN32_OPENGL
3700 #define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
3701 mod_gl = LoadLibraryA("opengl32.dll");
3702 if(!mod_gl) {
3703 ERR("Can't load opengl32.dll!\n");
3704 return FALSE;
3706 #else
3707 #define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
3708 /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
3709 mod_gl = GetModuleHandleA("gdi32.dll");
3710 #endif
3713 /* Load WGL core functions from opengl32.dll */
3714 #define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn);
3715 WGL_FUNCS_GEN;
3716 #undef USE_WGL_FUNC
3718 if(!pwglGetProcAddress) {
3719 ERR("Unable to load wglGetProcAddress!\n");
3720 return FALSE;
3723 /* Dynamically load all GL core functions */
3724 GL_FUNCS_GEN;
3725 #undef USE_GL_FUNC
3727 /* For now only one default adapter */
3729 int iPixelFormat;
3730 int attribs[8];
3731 int values[8];
3732 int nAttribs = 0;
3733 int res;
3734 WineD3D_PixelFormat *cfgs;
3735 int attribute;
3736 DISPLAY_DEVICEW DisplayDevice;
3737 HDC hdc;
3739 TRACE("Initializing default adapter\n");
3740 Adapters[0].num = 0;
3741 Adapters[0].monitorPoint.x = -1;
3742 Adapters[0].monitorPoint.y = -1;
3744 if (!WineD3D_CreateFakeGLContext()) {
3745 ERR("Failed to get a gl context for default adapter\n");
3746 HeapFree(GetProcessHeap(), 0, Adapters);
3747 WineD3D_ReleaseFakeGLContext();
3748 return FALSE;
3751 ret = IWineD3DImpl_FillGLCaps(&Adapters[0].gl_info);
3752 if(!ret) {
3753 ERR("Failed to initialize gl caps for default adapter\n");
3754 HeapFree(GetProcessHeap(), 0, Adapters);
3755 WineD3D_ReleaseFakeGLContext();
3756 return FALSE;
3758 ret = initPixelFormats(&Adapters[0].gl_info);
3759 if(!ret) {
3760 ERR("Failed to init gl formats\n");
3761 HeapFree(GetProcessHeap(), 0, Adapters);
3762 WineD3D_ReleaseFakeGLContext();
3763 return FALSE;
3766 hdc = pwglGetCurrentDC();
3767 if(!hdc) {
3768 ERR("Failed to get gl HDC\n");
3769 HeapFree(GetProcessHeap(), 0, Adapters);
3770 WineD3D_ReleaseFakeGLContext();
3771 return FALSE;
3774 Adapters[0].driver = "Display";
3775 Adapters[0].description = "Direct3D HAL";
3777 /* Use the VideoRamSize registry setting when set */
3778 if(wined3d_settings.emulated_textureram)
3779 Adapters[0].TextureRam = wined3d_settings.emulated_textureram;
3780 else
3781 Adapters[0].TextureRam = Adapters[0].gl_info.vidmem;
3782 Adapters[0].UsedTextureRam = 0;
3783 TRACE("Emulating %dMB of texture ram\n", Adapters[0].TextureRam/(1024*1024));
3785 /* Initialize the Adapter's DeviceName which is required for ChangeDisplaySettings and friends */
3786 DisplayDevice.cb = sizeof(DisplayDevice);
3787 EnumDisplayDevicesW(NULL, 0 /* Adapter 0 = iDevNum 0 */, &DisplayDevice, 0);
3788 TRACE("DeviceName: %s\n", debugstr_w(DisplayDevice.DeviceName));
3789 strcpyW(Adapters[0].DeviceName, DisplayDevice.DeviceName);
3791 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
3792 GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, &attribute, &Adapters[0].nCfgs));
3794 Adapters[0].cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Adapters[0].nCfgs *sizeof(WineD3D_PixelFormat));
3795 cfgs = Adapters[0].cfgs;
3796 PUSH1(WGL_RED_BITS_ARB)
3797 PUSH1(WGL_GREEN_BITS_ARB)
3798 PUSH1(WGL_BLUE_BITS_ARB)
3799 PUSH1(WGL_ALPHA_BITS_ARB)
3800 PUSH1(WGL_DEPTH_BITS_ARB)
3801 PUSH1(WGL_STENCIL_BITS_ARB)
3802 PUSH1(WGL_DRAW_TO_WINDOW_ARB)
3803 PUSH1(WGL_PIXEL_TYPE_ARB)
3805 for(iPixelFormat=1; iPixelFormat<=Adapters[0].nCfgs; iPixelFormat++) {
3806 res = GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, nAttribs, attribs, values));
3808 if(!res)
3809 continue;
3811 /* Cache the pixel format */
3812 cfgs->iPixelFormat = iPixelFormat;
3813 cfgs->redSize = values[0];
3814 cfgs->greenSize = values[1];
3815 cfgs->blueSize = values[2];
3816 cfgs->alphaSize = values[3];
3817 cfgs->depthSize = values[4];
3818 cfgs->stencilSize = values[5];
3819 cfgs->windowDrawable = values[6];
3820 cfgs->iPixelType = values[7];
3822 cfgs->pbufferDrawable = FALSE;
3823 /* Check for pbuffer support when it is around as wglGetPixelFormatAttribiv fails for unknown
3824 attributes. */
3825 if(GL_SUPPORT(WGL_ARB_PBUFFER)) {
3826 int attrib = WGL_DRAW_TO_PBUFFER_ARB;
3827 int value;
3828 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 1, &attrib, &value)))
3829 cfgs->pbufferDrawable = value;
3832 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);
3833 cfgs++;
3836 fixup_extensions(&Adapters[0].gl_info);
3838 WineD3D_ReleaseFakeGLContext();
3840 select_shader_mode(&Adapters[0].gl_info, WINED3DDEVTYPE_HAL, &ps_selected_mode, &vs_selected_mode);
3841 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &Adapters[0].gl_info);
3842 fillGLAttribFuncs(&Adapters[0].gl_info);
3843 init_type_lookup(&Adapters[0].gl_info);
3845 numAdapters = 1;
3846 TRACE("%d adapters successfully initialized\n", numAdapters);
3848 return TRUE;
3850 #undef PUSH1
3851 #undef GLINFO_LOCATION
3853 /**********************************************************
3854 * IWineD3D VTbl follows
3855 **********************************************************/
3857 const IWineD3DVtbl IWineD3D_Vtbl =
3859 /* IUnknown */
3860 IWineD3DImpl_QueryInterface,
3861 IWineD3DImpl_AddRef,
3862 IWineD3DImpl_Release,
3863 /* IWineD3D */
3864 IWineD3DImpl_GetParent,
3865 IWineD3DImpl_GetAdapterCount,
3866 IWineD3DImpl_RegisterSoftwareDevice,
3867 IWineD3DImpl_GetAdapterMonitor,
3868 IWineD3DImpl_GetAdapterModeCount,
3869 IWineD3DImpl_EnumAdapterModes,
3870 IWineD3DImpl_GetAdapterDisplayMode,
3871 IWineD3DImpl_GetAdapterIdentifier,
3872 IWineD3DImpl_CheckDeviceMultiSampleType,
3873 IWineD3DImpl_CheckDepthStencilMatch,
3874 IWineD3DImpl_CheckDeviceType,
3875 IWineD3DImpl_CheckDeviceFormat,
3876 IWineD3DImpl_CheckDeviceFormatConversion,
3877 IWineD3DImpl_GetDeviceCaps,
3878 IWineD3DImpl_CreateDevice