2 * IWineD3D implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wined3d_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
29 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
31 #define GLINFO_LOCATION (*gl_info)
33 /* The d3d device ID */
34 static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
36 /* Extension detection */
38 const char *extension_string;
39 GL_SupportedExt extension;
43 {"GL_APPLE_client_storage", APPLE_CLIENT_STORAGE, 0 },
44 {"GL_APPLE_fence", APPLE_FENCE, 0 },
45 {"GL_APPLE_flush_render", APPLE_FLUSH_RENDER, 0 },
46 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422, 0 },
47 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS, 0 },
50 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL, 0 },
51 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3, 0 },
52 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE, 0 },
53 {"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER, 0 },
54 {"GL_ATI_texture_compression_3dc", ATI_TEXTURE_COMPRESSION_3DC, 0 },
57 {"GL_ARB_color_buffer_float", ARB_COLOR_BUFFER_FLOAT, 0 },
58 {"GL_ARB_depth_buffer_float", ARB_DEPTH_BUFFER_FLOAT, 0 },
59 {"GL_ARB_depth_texture", ARB_DEPTH_TEXTURE, 0 },
60 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS, 0 },
61 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM, 0 },
62 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER, 0 },
63 {"GL_ARB_geometry_shader4", ARB_GEOMETRY_SHADER4, 0 },
64 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL, 0 },
65 {"GL_ARB_imaging", ARB_IMAGING, 0 },
66 {"GL_ARB_multisample", ARB_MULTISAMPLE, 0 }, /* needs GLX_ARB_MULTISAMPLE as well */
67 {"GL_ARB_multitexture", ARB_MULTITEXTURE, 0 },
68 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY, 0 },
69 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT, 0 },
70 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS, 0 },
71 {"GL_ARB_point_sprite", ARB_POINT_SPRITE, 0 },
72 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP, 0 },
73 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION, 0 },
74 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP, 0 },
75 {"GL_ARB_texture_env_add", ARB_TEXTURE_ENV_ADD, 0 },
76 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE, 0 },
77 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3, 0 },
78 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT, 0 },
79 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT, 0 },
80 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO, MAKEDWORD_VERSION(2, 0) },
81 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE, 0 },
82 {"GL_ARB_texture_rg", ARB_TEXTURE_RG, 0 },
83 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND, 0 },
84 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT, 0 },
85 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM, 0 },
86 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER, 0 },
87 {"GL_ARB_shader_objects", ARB_SHADER_OBJECTS, 0 },
88 {"GL_ARB_shader_texture_lod", ARB_SHADER_TEXTURE_LOD, 0 },
89 {"GL_ARB_half_float_vertex", ARB_HALF_FLOAT_VERTEX, 0 },
92 {"GL_EXT_blend_color", EXT_BLEND_COLOR, 0 },
93 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX, 0 },
94 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE, 0 },
95 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE, 0 },
96 {"GL_EXT_fog_coord", EXT_FOG_COORD, 0 },
97 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT, 0 },
98 {"GL_EXT_framebuffer_multisample", EXT_FRAMEBUFFER_MULTISAMPLE, 0 },
99 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT, 0 },
100 {"GL_EXT_packed_depth_stencil", EXT_PACKED_DEPTH_STENCIL, 0 },
101 {"GL_EXT_paletted_texture", EXT_PALETTED_TEXTURE, 0 },
102 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS, 0 },
103 {"GL_EXT_provoking_vertex", EXT_PROVOKING_VERTEX, 0 },
104 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR, 0 },
105 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE, 0 },
106 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP, 0 },
107 {"GL_EXT_texture3D", EXT_TEXTURE3D, MAKEDWORD_VERSION(1, 2) },
108 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC, 0 },
109 {"GL_EXT_texture_compression_rgtc", EXT_TEXTURE_COMPRESSION_RGTC, 0 },
110 {"GL_EXT_texture_env_add", EXT_TEXTURE_ENV_ADD, 0 },
111 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE, 0 },
112 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3, 0 },
113 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB, 0 },
114 {"GL_EXT_texture_swizzle", EXT_TEXTURE_SWIZZLE, 0 },
115 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC, 0 },
116 {"GL_EXT_texture_lod", EXT_TEXTURE_LOD, 0 },
117 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS, 0 },
118 {"GL_EXT_vertex_array_bgra", EXT_VERTEX_ARRAY_BGRA, 0 },
119 {"GL_EXT_vertex_shader", EXT_VERTEX_SHADER, 0 },
120 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS, 0 },
123 {"GL_NV_half_float", NV_HALF_FLOAT, 0 },
124 {"GL_NV_fence", NV_FENCE, 0 },
125 {"GL_NV_fog_distance", NV_FOG_DISTANCE, 0 },
126 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM, 0 },
127 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2, 0 },
128 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS, 0 },
129 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2, 0 },
130 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION, 0 },
131 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4, 0 },
132 {"GL_NV_texture_shader", NV_TEXTURE_SHADER, 0 },
133 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2, 0 },
134 {"GL_NV_texture_shader3", NV_TEXTURE_SHADER3, 0 },
135 {"GL_NV_occlusion_query", NV_OCCLUSION_QUERY, 0 },
136 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM, 0 },
137 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1, 0 },
138 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2, 0 },
139 {"GL_NV_vertex_program2_option", NV_VERTEX_PROGRAM2_OPTION, 0 },
140 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3, 0 },
141 {"GL_NV_fragment_program_option", NV_FRAGMENT_PROGRAM_OPTION, 0 },
142 {"GL_NV_depth_clamp", NV_DEPTH_CLAMP, 0 },
143 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT, 0 },
146 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP, 0 },
149 /**********************************************************
150 * Utility functions follow
151 **********************************************************/
153 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat, WINED3DSURFTYPE SurfaceType);
154 static const struct fragment_pipeline *select_fragment_implementation(struct WineD3DAdapter *adapter,
155 WINED3DDEVTYPE DeviceType);
156 static const shader_backend_t *select_shader_backend(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType);
157 static const struct blit_shader *select_blit_implementation(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType);
160 const int minLookup[MAX_LOOKUPS] =
162 WINED3DTADDRESS_WRAP, /* WINELOOKUP_WARPPARAM */
165 const int maxLookup[MAX_LOOKUPS] =
167 WINED3DTADDRESS_MIRRORONCE, /* WINELOOKUP_WARPPARAM */
170 DWORD *stateLookup[MAX_LOOKUPS];
172 const struct min_lookup minMipLookup[] =
174 /* NONE POINT LINEAR */
175 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
176 {{GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR}}, /* POINT*/
177 {{GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR}}, /* LINEAR */
180 const struct min_lookup minMipLookup_noFilter[] =
182 /* NONE POINT LINEAR */
183 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
184 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* POINT */
185 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* LINEAR */
188 const GLenum magLookup[] =
190 /* NONE POINT LINEAR */
191 GL_NEAREST, GL_NEAREST, GL_LINEAR,
194 const GLenum magLookup_noFilter[] =
196 /* NONE POINT LINEAR */
197 GL_NEAREST, GL_NEAREST, GL_NEAREST,
200 /* drawStridedSlow attributes */
201 glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT];
202 glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT];
203 glAttribFunc specular_func_3ubv;
204 glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT];
205 glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT];
206 glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT];
209 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created,
210 * i.e., there is no GL Context - Get a default rendering context to enable the
211 * function query some info from GL.
214 struct wined3d_fake_gl_ctx
221 static void WineD3D_ReleaseFakeGLContext(struct wined3d_fake_gl_ctx *ctx)
223 TRACE_(d3d_caps)("Destroying fake GL context.\n");
225 if (!pwglMakeCurrent(NULL, NULL))
227 ERR_(d3d_caps)("Failed to disable fake GL context.\n");
230 if (!pwglDeleteContext(ctx->gl_ctx))
232 DWORD err = GetLastError();
233 ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx->gl_ctx, err);
236 ReleaseDC(ctx->wnd, ctx->dc);
237 DestroyWindow(ctx->wnd);
240 static BOOL WineD3D_CreateFakeGLContext(struct wined3d_fake_gl_ctx *ctx)
242 PIXELFORMATDESCRIPTOR pfd;
245 TRACE("getting context...\n");
247 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes. */
248 ctx->wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window",
249 WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
252 ERR_(d3d_caps)("Failed to create a window.\n");
256 ctx->dc = GetDC(ctx->wnd);
259 ERR_(d3d_caps)("Failed to get a DC.\n");
263 /* PixelFormat selection */
264 ZeroMemory(&pfd, sizeof(pfd));
265 pfd.nSize = sizeof(pfd);
267 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; /* PFD_GENERIC_ACCELERATED */
268 pfd.iPixelType = PFD_TYPE_RGBA;
270 pfd.iLayerType = PFD_MAIN_PLANE;
272 iPixelFormat = ChoosePixelFormat(ctx->dc, &pfd);
275 /* If this happens something is very wrong as ChoosePixelFormat barely fails. */
276 ERR_(d3d_caps)("Can't find a suitable iPixelFormat.\n");
279 DescribePixelFormat(ctx->dc, iPixelFormat, sizeof(pfd), &pfd);
280 SetPixelFormat(ctx->dc, iPixelFormat, &pfd);
282 /* Create a GL context. */
283 ctx->gl_ctx = pwglCreateContext(ctx->dc);
286 WARN_(d3d_caps)("Error creating default context for capabilities initialization.\n");
290 /* Make it the current GL context. */
291 if (!context_set_current(NULL))
293 ERR_(d3d_caps)("Failed to clear current D3D context.\n");
296 if (!pwglMakeCurrent(ctx->dc, ctx->gl_ctx))
298 ERR_(d3d_caps)("Failed to make fake GL context current.\n");
305 if (ctx->gl_ctx) pwglDeleteContext(ctx->gl_ctx);
307 if (ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
309 if (ctx->wnd) DestroyWindow(ctx->wnd);
315 /* Adjust the amount of used texture memory */
316 long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram){
317 struct WineD3DAdapter *adapter = D3DDevice->adapter;
319 adapter->UsedTextureRam += glram;
320 TRACE("Adjusted gl ram by %ld to %d\n", glram, adapter->UsedTextureRam);
321 return adapter->UsedTextureRam;
324 /**********************************************************
325 * IUnknown parts follows
326 **********************************************************/
328 static HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
330 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
332 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
333 if (IsEqualGUID(riid, &IID_IUnknown)
334 || IsEqualGUID(riid, &IID_IWineD3DBase)
335 || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
336 IUnknown_AddRef(iface);
341 return E_NOINTERFACE;
344 static ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
345 IWineD3DImpl *This = (IWineD3DImpl *)iface;
346 ULONG refCount = InterlockedIncrement(&This->ref);
348 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
352 static ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
353 IWineD3DImpl *This = (IWineD3DImpl *)iface;
355 TRACE("(%p) : Releasing from %d\n", This, This->ref);
356 ref = InterlockedDecrement(&This->ref);
360 for (i = 0; i < This->adapter_count; ++i)
362 HeapFree(GetProcessHeap(), 0, This->adapters[i].cfgs);
364 HeapFree(GetProcessHeap(), 0, This);
370 /* Set the shader type for this device, depending on the given capabilities,
371 * the device type, and the user preferences in wined3d_settings */
373 static void select_shader_mode(const struct wined3d_gl_info *gl_info,
374 WINED3DDEVTYPE DeviceType, int *ps_selected, int *vs_selected)
376 if (wined3d_settings.vs_mode == VS_NONE) {
377 *vs_selected = SHADER_NONE;
378 } else if (gl_info->supported[ARB_VERTEX_SHADER] && wined3d_settings.glslRequested) {
379 /* Geforce4 cards support GLSL but for vertex shaders only. Further its reported GLSL caps are
380 * wrong. This combined with the fact that glsl won't offer more features or performance, use ARB
381 * shaders only on this card. */
382 if (gl_info->supported[NV_VERTEX_PROGRAM] && !gl_info->supported[NV_VERTEX_PROGRAM2])
383 *vs_selected = SHADER_ARB;
385 *vs_selected = SHADER_GLSL;
386 } else if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
387 *vs_selected = SHADER_ARB;
389 *vs_selected = SHADER_NONE;
392 if (wined3d_settings.ps_mode == PS_NONE) {
393 *ps_selected = SHADER_NONE;
394 } else if (gl_info->supported[ARB_FRAGMENT_SHADER] && wined3d_settings.glslRequested) {
395 *ps_selected = SHADER_GLSL;
396 } else if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
397 *ps_selected = SHADER_ARB;
398 } else if (gl_info->supported[ATI_FRAGMENT_SHADER]) {
399 *ps_selected = SHADER_ATI;
401 *ps_selected = SHADER_NONE;
405 /** Select the number of report maximum shader constants based on the selected shader modes */
406 static void select_shader_max_constants(int ps_selected_mode, int vs_selected_mode, struct wined3d_gl_info *gl_info)
408 switch (vs_selected_mode) {
410 gl_info->max_vshader_constantsF = gl_info->vs_glsl_constantsF;
413 gl_info->max_vshader_constantsF = gl_info->vs_arb_constantsF;
416 gl_info->max_vshader_constantsF = 0;
420 switch (ps_selected_mode) {
422 gl_info->max_pshader_constantsF = gl_info->ps_glsl_constantsF;
425 gl_info->max_pshader_constantsF = gl_info->ps_arb_constantsF;
428 gl_info->max_pshader_constantsF = 0;
433 /**********************************************************
434 * IWineD3D parts follows
435 **********************************************************/
437 /* GL locking is done by the caller */
438 static inline BOOL test_arb_vs_offset_limit(const struct wined3d_gl_info *gl_info)
442 const char *testcode =
444 "PARAM C[66] = { program.env[0..65] };\n"
446 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
447 "ARL A0.x, zero.x;\n"
448 "MOV result.position, C[A0.x + 65];\n"
452 GL_EXTCALL(glGenProgramsARB(1, &prog));
454 ERR("Failed to create an ARB offset limit test program\n");
456 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
457 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
458 strlen(testcode), testcode));
459 if(glGetError() != 0) {
460 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
461 TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
463 } else TRACE("OpenGL implementation allows offsets > 63\n");
465 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
466 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
467 checkGLcall("ARB vp offset limit test cleanup");
472 static DWORD ver_for_ext(GL_SupportedExt ext)
475 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
476 if(EXTENSION_MAP[i].extension == ext) {
477 return EXTENSION_MAP[i].version;
483 static BOOL match_ati_r300_to_500(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
485 if (gl_info->gl_vendor != VENDOR_ATI) return FALSE;
486 if (gl_info->gl_card == CARD_ATI_RADEON_9500) return TRUE;
487 if (gl_info->gl_card == CARD_ATI_RADEON_X700) return TRUE;
488 if (gl_info->gl_card == CARD_ATI_RADEON_X1600) return TRUE;
492 static BOOL match_geforce5(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
494 if (gl_info->gl_vendor == VENDOR_NVIDIA)
496 if (gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5800 || gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5600)
504 static BOOL match_apple(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
506 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
507 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
508 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
510 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
511 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
512 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
513 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
514 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
515 * the chance that other implementations support them is rather small since Win32 QuickTime uses
516 * DirectDraw, not OpenGL. */
517 if (gl_info->supported[APPLE_FENCE]
518 && gl_info->supported[APPLE_CLIENT_STORAGE]
519 && gl_info->supported[APPLE_FLUSH_RENDER]
520 && gl_info->supported[APPLE_YCBCR_422])
522 TRACE_(d3d_caps)("GL_APPLE_fence, GL_APPLE_client_storage, GL_APPLE_flush_render and GL_ycbcr_422 are supported.\n");
523 TRACE_(d3d_caps)("Activating MacOS fixups.\n");
528 TRACE_(d3d_caps)("Apple extensions are not supported.\n");
529 TRACE_(d3d_caps)("Not activating MacOS fixups.\n");
534 /* Context activation is done by the caller. */
535 static void test_pbo_functionality(struct wined3d_gl_info *gl_info)
537 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
538 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
539 * all the texture. This function detects this bug by its symptom and disables PBOs
542 * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
543 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
544 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
545 * read back is compared to the original. If they are equal PBOs are assumed to work,
546 * otherwise the PBO extension is disabled. */
548 static const unsigned int pattern[] =
550 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
551 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
552 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
553 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
555 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
557 /* No PBO -> No point in testing them. */
558 if (!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) return;
562 while (glGetError());
563 glGenTextures(1, &texture);
564 glBindTexture(GL_TEXTURE_2D, texture);
566 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
567 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
568 checkGLcall("Specifying the PBO test texture");
570 GL_EXTCALL(glGenBuffersARB(1, &pbo));
571 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
572 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
573 checkGLcall("Specifying the PBO test pbo");
575 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
576 checkGLcall("Loading the PBO test texture");
578 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
579 wglFinish(); /* just to be sure */
581 memset(check, 0, sizeof(check));
582 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
583 checkGLcall("Reading back the PBO test texture");
585 glDeleteTextures(1, &texture);
586 GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
587 checkGLcall("PBO test cleanup");
591 if (memcmp(check, pattern, sizeof(check)))
593 WARN_(d3d_caps)("PBO test failed, read back data doesn't match original.\n");
594 WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance.\n");
595 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
599 TRACE_(d3d_caps)("PBO test successful.\n");
603 static BOOL match_apple_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
605 return gl_info->gl_vendor == VENDOR_INTEL && match_apple(gl_info, gl_renderer);
608 static BOOL match_apple_nonr500ati(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
610 if (!match_apple(gl_info, gl_renderer)) return FALSE;
611 if (gl_info->gl_vendor != VENDOR_ATI) return FALSE;
612 if (gl_info->gl_card == CARD_ATI_RADEON_X1600) return FALSE;
616 static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
618 if (gl_info->gl_vendor != VENDOR_ATI) return FALSE;
619 if (match_apple(gl_info, gl_renderer)) return FALSE;
620 if (strstr(gl_renderer, "DRI")) return FALSE; /* Filter out Mesa DRI drivers. */
624 static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
626 /* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
627 * 44 varyings. So assume that if we have more than 44 varyings we have a dx10 card.
628 * This detection is for the gl_ClipPos varying quirk. If a d3d9 card really supports more than 44
629 * varyings and we subtract one in dx9 shaders its not going to hurt us because the dx9 limit is
632 * dx10 cards usually have 64 varyings */
633 return gl_info->max_glsl_varyings > 44;
636 /* A GL context is provided by the caller */
637 static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
642 if(!GL_SUPPORT(EXT_SECONDARY_COLOR)) return FALSE;
646 GL_EXTCALL(glSecondaryColorPointerEXT)(4, GL_UNSIGNED_BYTE, 4, data);
647 error = glGetError();
650 if(error == GL_NO_ERROR)
652 TRACE("GL Implementation accepts 4 component specular color pointers\n");
657 TRACE("GL implementation does not accept 4 component specular colors, error %s\n",
658 debug_glerror(error));
663 static void quirk_arb_constants(struct wined3d_gl_info *gl_info)
665 TRACE_(d3d_caps)("Using ARB vs constant limit(=%u) for GLSL.\n", gl_info->vs_arb_constantsF);
666 gl_info->vs_glsl_constantsF = gl_info->vs_arb_constantsF;
667 TRACE_(d3d_caps)("Using ARB ps constant limit(=%u) for GLSL.\n", gl_info->ps_arb_constantsF);
668 gl_info->ps_glsl_constantsF = gl_info->ps_arb_constantsF;
671 static void quirk_apple_glsl_constants(struct wined3d_gl_info *gl_info)
673 quirk_arb_constants(gl_info);
674 /* MacOS needs uniforms for relative addressing offsets. This can accumulate to quite a few uniforms.
675 * Beyond that the general uniform isn't optimal, so reserve a number of uniforms. 12 vec4's should
676 * allow 48 different offsets or other helper immediate values. */
677 TRACE_(d3d_caps)("Reserving 12 GLSL constants for compiler private use.\n");
678 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
681 /* fglrx crashes with a very bad kernel panic if GL_POINT_SPRITE_ARB is set to GL_COORD_REPLACE_ARB
682 * on more than one texture unit. This means that the d3d9 visual point size test will cause a
683 * kernel panic on any machine running fglrx 9.3(latest that supports r300 to r500 cards). This
684 * quirk only enables point sprites on the first texture unit. This keeps point sprites working in
685 * most games, but avoids the crash
687 * A more sophisticated way would be to find all units that need texture coordinates and enable
688 * point sprites for one if only one is found, and software emulate point sprites in drawStridedSlow
689 * if more than one unit needs texture coordinates(This requires software ffp and vertex shaders though)
691 * Note that disabling the extension entirely does not gain predictability because there is no point
692 * sprite capability flag in d3d, so the potential rendering bugs are the same if we disable the extension. */
693 static void quirk_one_point_sprite(struct wined3d_gl_info *gl_info)
695 if (gl_info->supported[ARB_POINT_SPRITE])
697 TRACE("Limiting point sprites to one texture unit.\n");
698 gl_info->max_point_sprite_units = 1;
702 static void quirk_ati_dx9(struct wined3d_gl_info *gl_info)
704 quirk_arb_constants(gl_info);
706 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
707 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
708 * If real NP2 textures are used, the driver falls back to software. We could just remove the
709 * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconventient
710 * due to the non-normalized texture coordinates. Thus set an internal extension flag,
711 * GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures
712 * as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits.
714 * fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it advertises opengl 2.0 which
715 * has this extension promoted to core. The extension loading code sets this extension supported
716 * due to that, so this code works on fglrx as well. */
717 if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
719 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing.\n");
720 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
721 gl_info->supported[WINE_NORMALIZED_TEXRECT] = TRUE;
724 /* fglrx has the same structural issues as the one described in quirk_apple_glsl_constants, although
725 * it is generally more efficient. Reserve just 8 constants. */
726 TRACE_(d3d_caps)("Reserving 8 GLSL constants for compiler private use.\n");
727 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 8);
730 static void quirk_no_np2(struct wined3d_gl_info *gl_info)
732 /* The nVidia GeForceFX series reports OpenGL 2.0 capabilities with the latest drivers versions, but
733 * doesn't explicitly advertise the ARB_tex_npot extension in the GL extension string.
734 * This usually means that ARB_tex_npot is supported in hardware as long as the application is staying
735 * within the limits enforced by the ARB_texture_rectangle extension. This however is not true for the
736 * FX series, which instantly falls back to a slower software path as soon as ARB_tex_npot is used.
737 * We therefore completely remove ARB_tex_npot from the list of supported extensions.
739 * Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot,
740 * triggering the software fallback. There is not much we can do here apart from disabling the
741 * software-emulated extension and reenable ARB_tex_rect (which was previously disabled
742 * in IWineD3DImpl_FillGLCaps).
743 * This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer
744 * post-processing effects in the game "Max Payne 2").
745 * The behaviour can be verified through a simple test app attached in bugreport #14724. */
746 TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing.\n");
747 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
748 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
751 static void quirk_texcoord_w(struct wined3d_gl_info *gl_info)
753 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
754 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
755 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
756 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
757 * according to the spec.
759 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
760 * makes the shader slower and eats instruction slots which should be available to the d3d app.
762 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
763 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
764 * this workaround is activated on cards that do not need it, it won't break things, just affect
765 * performance negatively. */
766 TRACE("Enabling vertex texture coord fixes in vertex shaders.\n");
767 gl_info->quirks |= WINED3D_QUIRK_SET_TEXCOORD_W;
770 static void quirk_clip_varying(struct wined3d_gl_info *gl_info)
772 gl_info->quirks |= WINED3D_QUIRK_GLSL_CLIP_VARYING;
775 static void quirk_allows_specular_alpha(struct wined3d_gl_info *gl_info)
777 gl_info->quirks |= WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA;
782 BOOL (*match)(const struct wined3d_gl_info *gl_info, const char *gl_renderer);
783 void (*apply)(struct wined3d_gl_info *gl_info);
784 const char *description;
787 struct driver_quirk quirk_table[] =
790 match_ati_r300_to_500,
792 "ATI GLSL constant and normalized texrect quirk"
794 /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
795 * used it falls back to software. While the compiler can detect if the shader uses all declared
796 * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
797 * using relative addressing falls back to software.
799 * ARB vp gives the correct amount of uniforms, so use it instead of GLSL. */
802 quirk_apple_glsl_constants,
803 "Apple GLSL uniform override"
808 "Geforce 5 NP2 disable"
813 "Init texcoord .w for Apple Intel GPU driver"
816 match_apple_nonr500ati,
818 "Init texcoord .w for Apple ATI >= r600 GPU driver"
822 quirk_one_point_sprite,
823 "Fglrx point sprite crash workaround"
828 "Reserved varying for gl_ClipPos"
831 /* GL_EXT_secondary_color does not allow 4 component secondary colors, but most
832 * GL implementations accept it. The Mac GL is the only implementation known to
835 * If we can pass 4 component specular colors, do it, because (a) we don't have
836 * to screw around with the data, and (b) the D3D fixed function vertex pipeline
837 * passes specular alpha to the pixel shader if any is used. Otherwise the
838 * specular alpha is used to pass the fog coordinate, which we pass to opengl
839 * via GL_EXT_fog_coord.
841 match_allows_spec_alpha,
842 quirk_allows_specular_alpha,
843 "Allow specular alpha quirk"
847 /* Certain applications (Steam) complain if we report an outdated driver version. In general,
848 * reporting a driver version is moot because we are not the Windows driver, and we have different
849 * bugs, features, etc.
851 * If a card is not found in this table, the GL driver version is reported. */
852 struct driver_version_information
854 WORD vendor; /* reported PCI card vendor ID */
855 WORD card; /* reported PCI card device ID */
856 const char *description; /* Description of the card e.g. NVIDIA RIVA TNT */
857 WORD hipart_hi, hipart_lo; /* driver hiword to report */
858 WORD lopart_hi, lopart_lo; /* driver loword to report */
861 static const struct driver_version_information driver_version_table[] =
863 /* Nvidia drivers. Geforce6 and newer cards are supported by the current driver (180.x)
864 * GeforceFX support is up to 173.x, - driver uses numbering x.y.11.7341 for 173.41 where x is the windows revision (6=2000/xp, 7=vista), y is unknown
865 * Geforce2MX/3/4 up to 96.x - driver uses numbering 9.6.8.9 for 96.89
866 * TNT/Geforce1/2 up to 71.x - driver uses numbering 7.1.8.6 for 71.86
868 * All version numbers used below are from the Linux nvidia drivers. */
869 {VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT, "NVIDIA RIVA TNT", 7, 1, 8, 6 },
870 {VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT2, "NVIDIA RIVA TNT2/TNT2 Pro", 7, 1, 8, 6 },
871 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE, "NVIDIA GeForce 256", 7, 1, 8, 6 },
872 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2_MX, "NVIDIA GeForce2 MX/MX 400", 9, 6, 4, 3 },
873 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2, "NVIDIA GeForce2 GTS/GeForce2 Pro", 7, 1, 8, 6 },
874 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE3, "NVIDIA GeForce3", 9, 6, 10, 9371 },
875 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_MX, "NVIDIA GeForce4 MX 460", 9, 6, 10, 9371 },
876 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_TI4200, "NVIDIA GeForce4 Ti 4200", 9, 6, 10, 9371 },
877 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, "NVIDIA GeForce FX 5200", 7, 15, 11, 7516 },
878 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, "NVIDIA GeForce FX 5600", 7, 15, 11, 7516 },
879 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, "NVIDIA GeForce FX 5800", 7, 15, 11, 7516 },
880 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, "NVIDIA GeForce 6200", 7, 15, 11, 8618 },
881 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, "NVIDIA GeForce 6600 GT", 7, 15, 11, 8618 },
882 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, "NVIDIA GeForce 6800", 7, 15, 11, 8618 },
883 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, "NVIDIA GeForce Go 7300", 7, 15, 11, 8585 },
884 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, "NVIDIA GeForce Go 7400", 7, 15, 11, 8585 },
885 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, "NVIDIA GeForce 7600 GT", 7, 15, 11, 8618 },
886 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, "NVIDIA GeForce 7800 GT", 7, 15, 11, 8618 },
887 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, "NVIDIA GeForce 8300 GS", 7, 15, 11, 8618 },
888 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, "NVIDIA GeForce 8600 GT", 7, 15, 11, 8618 },
889 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, "NVIDIA GeForce 8600M GT", 7, 15, 11, 8585 },
890 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, "NVIDIA GeForce 8800 GTS", 7, 15, 11, 8618 },
891 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9200, "NVIDIA GeForce 9200", 7, 15, 11, 8618 },
892 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400GT, "NVIDIA GeForce 9400 GT", 7, 15, 11, 8618 },
893 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9500GT, "NVIDIA GeForce 9500 GT", 7, 15, 11, 8618 },
894 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9600GT, "NVIDIA GeForce 9600 GT", 7, 15, 11, 8618 },
895 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9800GT, "NVIDIA GeForce 9800 GT", 7, 15, 11, 8618 },
896 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX260, "NVIDIA GeForce GTX 260", 7, 15, 11, 8618 },
897 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX275, "NVIDIA GeForce GTX 275", 7, 15, 11, 8618 },
898 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX280, "NVIDIA GeForce GTX 280", 7, 15, 11, 8618 },
900 /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode. */
901 {VENDOR_ATI, CARD_ATI_RADEON_9500, "ATI Radeon 9500", 6, 14, 10, 6764 },
902 {VENDOR_ATI, CARD_ATI_RADEON_X700, "ATI Radeon X700 SE", 6, 14, 10, 6764 },
903 {VENDOR_ATI, CARD_ATI_RADEON_X1600, "ATI Radeon X1600 Series", 6, 14, 10, 6764 },
904 {VENDOR_ATI, CARD_ATI_RADEON_HD2300, "ATI Mobility Radeon HD 2300", 6, 14, 10, 6764 },
905 {VENDOR_ATI, CARD_ATI_RADEON_HD2600, "ATI Mobility Radeon HD 2600", 6, 14, 10, 6764 },
906 {VENDOR_ATI, CARD_ATI_RADEON_HD2900, "ATI Radeon HD 2900 XT", 6, 14, 10, 6764 },
907 {VENDOR_ATI, CARD_ATI_RADEON_HD4350, "ATI Radeon HD 4350", 6, 14, 10, 6764 },
908 {VENDOR_ATI, CARD_ATI_RADEON_HD4600, "ATI Radeon HD 4600 Series", 6, 14, 10, 6764 },
909 {VENDOR_ATI, CARD_ATI_RADEON_HD4700, "ATI Radeon HD 4700 Series", 6, 14, 10, 6764 },
910 {VENDOR_ATI, CARD_ATI_RADEON_HD4800, "ATI Radeon HD 4800 Series", 6, 14, 10, 6764 },
912 /* TODO: Add information about legacy ATI hardware, Intel and other cards. */
915 /* Context activation is done by the caller. */
916 static void fixup_extensions(struct wined3d_gl_info *gl_info, const char *gl_renderer)
920 for (i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); ++i)
922 if (!quirk_table[i].match(gl_info, gl_renderer)) continue;
923 TRACE_(d3d_caps)("Applying driver quirk \"%s\".\n", quirk_table[i].description);
924 quirk_table[i].apply(gl_info);
927 /* Find out if PBOs work as they are supposed to. */
928 test_pbo_functionality(gl_info);
930 /* Fixup the driver version we'll report to the app. */
931 gl_info->driver_version = MAKEDWORD_VERSION(8, 6); /* Nvidia RIVA TNT, arbitrary */
932 gl_info->driver_version_hipart = MAKEDWORD_VERSION(7, 1);
933 for (i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); ++i)
935 if (gl_info->gl_vendor == driver_version_table[i].vendor
936 && gl_info->gl_card == driver_version_table[i].card)
938 TRACE_(d3d_caps)("Found card 0x%04x, 0x%04x in driver version DB.\n",
939 gl_info->gl_vendor, gl_info->gl_card);
941 gl_info->driver_version = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
942 driver_version_table[i].lopart_lo);
943 gl_info->driver_version_hipart = MAKEDWORD_VERSION(driver_version_table[i].hipart_hi,
944 driver_version_table[i].hipart_lo);
945 gl_info->driver_description = driver_version_table[i].description;
949 TRACE_(d3d_caps)("Reporting (fake) driver version 0x%08X-0x%08X.\n",
950 gl_info->driver_version_hipart, gl_info->driver_version);
953 static DWORD wined3d_parse_gl_version(const char *gl_version)
955 const char *ptr = gl_version;
959 if (major <= 0) ERR_(d3d_caps)("Invalid opengl major version: %d.\n", major);
961 while (isdigit(*ptr)) ++ptr;
962 if (*ptr++ != '.') ERR_(d3d_caps)("Invalid opengl version string: %s.\n", debugstr_a(gl_version));
966 TRACE_(d3d_caps)("Found OpenGL version: %d.%d.\n", major, minor);
968 return MAKEDWORD_VERSION(major, minor);
971 static GL_Vendors wined3d_guess_vendor(const char *gl_vendor, const char *gl_renderer)
973 if (strstr(gl_vendor, "NVIDIA"))
974 return VENDOR_NVIDIA;
976 if (strstr(gl_vendor, "ATI"))
979 if (strstr(gl_vendor, "Intel(R)")
980 || strstr(gl_renderer, "Intel(R)")
981 || strstr(gl_vendor, "Intel Inc."))
984 if (strstr(gl_vendor, "Mesa")
985 || strstr(gl_vendor, "Tungsten Graphics, Inc."))
988 FIXME_(d3d_caps)("Received unrecognized GL_VENDOR %s. Returning VENDOR_WINE.\n", debugstr_a(gl_vendor));
993 static GL_Cards wined3d_guess_card(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
994 GL_Vendors *vendor, unsigned int *vidmem)
996 /* Below is a list of Nvidia and ATI GPUs. Both vendors have dozens of
997 * different GPUs with roughly the same features. In most cases GPUs from a
998 * certain family differ in clockspeeds, the amount of video memory and the
999 * number of shader pipelines.
1001 * A Direct3D device object contains the PCI id (vendor + device) of the
1002 * videocard which is used for rendering. Various applications use this
1003 * information to get a rough estimation of the features of the card and
1004 * some might use it for enabling 3d effects only on certain types of
1005 * videocards. In some cases games might even use it to work around bugs
1006 * which happen on certain videocards/driver combinations. The problem is
1007 * that OpenGL only exposes a rendering string containing the name of the
1008 * videocard and not the PCI id.
1010 * Various games depend on the PCI id, so somehow we need to provide one.
1011 * A simple option is to parse the renderer string and translate this to
1012 * the right PCI id. This is a lot of work because there are more than 200
1013 * GPUs just for Nvidia. Various cards share the same renderer string, so
1014 * the amount of code might be 'small' but there are quite a number of
1015 * exceptions which would make this a pain to maintain. Another way would
1016 * be to query the PCI id from the operating system (assuming this is the
1017 * videocard which is used for rendering which is not always the case).
1018 * This would work but it is not very portable. Second it would not work
1019 * well in, let's say, a remote X situation in which the amount of 3d
1020 * features which can be used is limited.
1022 * As said most games only use the PCI id to get an indication of the
1023 * capabilities of the card. It doesn't really matter if the given id is
1024 * the correct one if we return the id of a card with similar 3d features.
1026 * The code below checks the OpenGL capabilities of a videocard and matches
1027 * that to a certain level of Direct3D functionality. Once a card passes
1028 * the Direct3D9 check, we know that the card (in case of Nvidia) is at
1029 * least a GeforceFX. To give a better estimate we do a basic check on the
1030 * renderer string but if that won't pass we return a default card. This
1031 * way is better than maintaining a full card database as even without a
1032 * full database we can return a card with similar features. Second the
1033 * size of the database can be made quite small because when you know what
1034 * type of 3d functionality a card has, you know to which GPU family the
1035 * GPU must belong. Because of this you only have to check a small part of
1036 * the renderer string to distinguishes between different models from that
1039 * The code also selects a default amount of video memory which we will
1040 * use for an estimation of the amount of free texture memory. In case of
1041 * real D3D the amount of texture memory includes video memory and system
1042 * memory (to be specific AGP memory or in case of PCIE TurboCache /
1043 * HyperMemory). We don't know how much system memory can be addressed by
1044 * the system but we can make a reasonable estimation about the amount of
1045 * video memory. If the value is slightly wrong it doesn't matter as we
1046 * didn't include AGP-like memory which makes the amount of addressable
1047 * memory higher and second OpenGL isn't that critical it moves to system
1048 * memory behind our backs if really needed. Note that the amount of video
1049 * memory can be overruled using a registry setting. */
1054 /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1055 * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1057 if (WINE_D3D9_CAPABLE(gl_info) && gl_info->supported[NV_VERTEX_PROGRAM3])
1059 /* Geforce 200 - highend */
1060 if (strstr(gl_renderer, "GTX 280")
1061 || strstr(gl_renderer, "GTX 285")
1062 || strstr(gl_renderer, "GTX 295"))
1065 return CARD_NVIDIA_GEFORCE_GTX280;
1068 /* Geforce 200 - midend high */
1069 if (strstr(gl_renderer, "GTX 275"))
1072 return CARD_NVIDIA_GEFORCE_GTX275;
1075 /* Geforce 200 - midend */
1076 if (strstr(gl_renderer, "GTX 260"))
1079 return CARD_NVIDIA_GEFORCE_GTX260;
1082 /* Geforce9 - highend / Geforce 200 - midend (GTS 150/250 are based on the same core) */
1083 if (strstr(gl_renderer, "9800")
1084 || strstr(gl_renderer, "GTS 150")
1085 || strstr(gl_renderer, "GTS 250"))
1088 return CARD_NVIDIA_GEFORCE_9800GT;
1091 /* Geforce9 - midend */
1092 if (strstr(gl_renderer, "9600"))
1094 *vidmem = 384; /* The 9600GSO has 384MB, the 9600GT has 512-1024MB */
1095 return CARD_NVIDIA_GEFORCE_9600GT;
1098 /* Geforce9 - midend low / Geforce 200 - low */
1099 if (strstr(gl_renderer, "9500")
1100 || strstr(gl_renderer, "GT 120")
1101 || strstr(gl_renderer, "GT 130"))
1103 *vidmem = 256; /* The 9500GT has 256-1024MB */
1104 return CARD_NVIDIA_GEFORCE_9500GT;
1107 /* Geforce9 - lowend */
1108 if (strstr(gl_renderer, "9400"))
1110 *vidmem = 256; /* The 9400GT has 256-1024MB */
1111 return CARD_NVIDIA_GEFORCE_9400GT;
1114 /* Geforce9 - lowend low */
1115 if (strstr(gl_renderer, "9100")
1116 || strstr(gl_renderer, "9200")
1117 || strstr(gl_renderer, "9300")
1118 || strstr(gl_renderer, "G 100"))
1120 *vidmem = 256; /* The 9100-9300 cards have 256MB */
1121 return CARD_NVIDIA_GEFORCE_9200;
1124 /* Geforce8 - highend */
1125 if (strstr(gl_renderer, "8800"))
1127 *vidmem = 320; /* The 8800GTS uses 320MB, a 8800GTX can have 768MB */
1128 return CARD_NVIDIA_GEFORCE_8800GTS;
1131 /* Geforce8 - midend mobile */
1132 if (strstr(gl_renderer, "8600 M"))
1135 return CARD_NVIDIA_GEFORCE_8600MGT;
1138 /* Geforce8 - midend */
1139 if (strstr(gl_renderer, "8600")
1140 || strstr(gl_renderer, "8700"))
1143 return CARD_NVIDIA_GEFORCE_8600GT;
1146 /* Geforce8 - lowend */
1147 if (strstr(gl_renderer, "8300")
1148 || strstr(gl_renderer, "8400")
1149 || strstr(gl_renderer, "8500"))
1151 *vidmem = 128; /* 128-256MB for a 8300, 256-512MB for a 8400 */
1152 return CARD_NVIDIA_GEFORCE_8300GS;
1155 /* Geforce7 - highend */
1156 if (strstr(gl_renderer, "7800")
1157 || strstr(gl_renderer, "7900")
1158 || strstr(gl_renderer, "7950")
1159 || strstr(gl_renderer, "Quadro FX 4")
1160 || strstr(gl_renderer, "Quadro FX 5"))
1162 *vidmem = 256; /* A 7800GT uses 256MB while highend 7900 cards can use 512MB */
1163 return CARD_NVIDIA_GEFORCE_7800GT;
1166 /* Geforce7 midend */
1167 if (strstr(gl_renderer, "7600")
1168 || strstr(gl_renderer, "7700"))
1170 *vidmem = 256; /* The 7600 uses 256-512MB */
1171 return CARD_NVIDIA_GEFORCE_7600;
1174 /* Geforce7 lower medium */
1175 if (strstr(gl_renderer, "7400"))
1177 *vidmem = 256; /* The 7400 uses 256-512MB */
1178 return CARD_NVIDIA_GEFORCE_7400;
1181 /* Geforce7 lowend */
1182 if (strstr(gl_renderer, "7300"))
1184 *vidmem = 256; /* Mac Pros with this card have 256 MB */
1185 return CARD_NVIDIA_GEFORCE_7300;
1188 /* Geforce6 highend */
1189 if (strstr(gl_renderer, "6800"))
1191 *vidmem = 128; /* The 6800 uses 128-256MB, the 7600 uses 256-512MB */
1192 return CARD_NVIDIA_GEFORCE_6800;
1195 /* Geforce6 - midend */
1196 if (strstr(gl_renderer, "6600")
1197 || strstr(gl_renderer, "6610")
1198 || strstr(gl_renderer, "6700"))
1200 *vidmem = 128; /* A 6600GT has 128-256MB */
1201 return CARD_NVIDIA_GEFORCE_6600GT;
1204 /* Geforce6/7 lowend */
1206 return CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
1209 if (WINE_D3D9_CAPABLE(gl_info))
1211 /* GeforceFX - highend */
1212 if (strstr(gl_renderer, "5800")
1213 || strstr(gl_renderer, "5900")
1214 || strstr(gl_renderer, "5950")
1215 || strstr(gl_renderer, "Quadro FX"))
1217 *vidmem = 256; /* 5800-5900 cards use 256MB */
1218 return CARD_NVIDIA_GEFORCEFX_5800;
1221 /* GeforceFX - midend */
1222 if (strstr(gl_renderer, "5600")
1223 || strstr(gl_renderer, "5650")
1224 || strstr(gl_renderer, "5700")
1225 || strstr(gl_renderer, "5750"))
1227 *vidmem = 128; /* A 5600 uses 128-256MB */
1228 return CARD_NVIDIA_GEFORCEFX_5600;
1231 /* GeforceFX - lowend */
1232 *vidmem = 64; /* Normal FX5200 cards use 64-256MB; laptop (non-standard) can have less */
1233 return CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1236 if (WINE_D3D8_CAPABLE(gl_info))
1238 if (strstr(gl_renderer, "GeForce4 Ti") || strstr(gl_renderer, "Quadro4"))
1240 *vidmem = 64; /* Geforce4 Ti cards have 64-128MB */
1241 return CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1244 *vidmem = 64; /* Geforce3 cards have 64-128MB */
1245 return CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1248 if (WINE_D3D7_CAPABLE(gl_info))
1250 if (strstr(gl_renderer, "GeForce4 MX"))
1252 /* Most Geforce4MX GPUs have at least 64MB of memory, some
1253 * early models had 32MB but most have 64MB or even 128MB. */
1255 return CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1258 if (strstr(gl_renderer, "GeForce2 MX") || strstr(gl_renderer, "Quadro2 MXR"))
1260 *vidmem = 32; /* Geforce2MX GPUs have 32-64MB of video memory */
1261 return CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1264 if (strstr(gl_renderer, "GeForce2") || strstr(gl_renderer, "Quadro2"))
1266 *vidmem = 32; /* Geforce2 GPUs have 32-64MB of video memory */
1267 return CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1270 /* Most Geforce1 cards have 32MB, there are also some rare 16
1271 * and 64MB (Dell) models. */
1273 return CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1276 if (strstr(gl_renderer, "TNT2"))
1278 *vidmem = 32; /* Most TNT2 boards have 32MB, though there are 16MB boards too */
1279 return CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1282 *vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
1283 return CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1286 /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx
1288 * Beware: renderer string do not match exact card model,
1289 * eg HD 4800 is returned for multiple cards, even for RV790 based ones. */
1290 if (WINE_D3D9_CAPABLE(gl_info))
1292 /* Radeon R7xx HD4800 - highend */
1293 if (strstr(gl_renderer, "HD 4800") /* Radeon RV7xx HD48xx generic renderer string */
1294 || strstr(gl_renderer, "HD 4830") /* Radeon RV770 */
1295 || strstr(gl_renderer, "HD 4850") /* Radeon RV770 */
1296 || strstr(gl_renderer, "HD 4870") /* Radeon RV770 */
1297 || strstr(gl_renderer, "HD 4890")) /* Radeon RV790 */
1299 *vidmem = 512; /* note: HD4890 cards use 1024MB */
1300 return CARD_ATI_RADEON_HD4800;
1303 /* Radeon R740 HD4700 - midend */
1304 if (strstr(gl_renderer, "HD 4700") /* Radeon RV770 */
1305 || strstr(gl_renderer, "HD 4770")) /* Radeon RV740 */
1308 return CARD_ATI_RADEON_HD4700;
1311 /* Radeon R730 HD4600 - midend */
1312 if (strstr(gl_renderer, "HD 4600") /* Radeon RV730 */
1313 || strstr(gl_renderer, "HD 4650") /* Radeon RV730 */
1314 || strstr(gl_renderer, "HD 4670")) /* Radeon RV730 */
1317 return CARD_ATI_RADEON_HD4600;
1320 /* Radeon R710 HD4500/HD4350 - lowend */
1321 if (strstr(gl_renderer, "HD 4350") /* Radeon RV710 */
1322 || strstr(gl_renderer, "HD 4550")) /* Radeon RV710 */
1325 return CARD_ATI_RADEON_HD4350;
1328 /* Radeon R6xx HD2900/HD3800 - highend */
1329 if (strstr(gl_renderer, "HD 2900")
1330 || strstr(gl_renderer, "HD 3870")
1331 || strstr(gl_renderer, "HD 3850"))
1333 *vidmem = 512; /* HD2900/HD3800 uses 256-1024MB */
1334 return CARD_ATI_RADEON_HD2900;
1337 /* Radeon R6xx HD2600/HD3600 - midend; HD3830 is China-only midend */
1338 if (strstr(gl_renderer, "HD 2600")
1339 || strstr(gl_renderer, "HD 3830")
1340 || strstr(gl_renderer, "HD 3690")
1341 || strstr(gl_renderer, "HD 3650"))
1343 *vidmem = 256; /* HD2600/HD3600 uses 256-512MB */
1344 return CARD_ATI_RADEON_HD2600;
1347 /* Radeon R6xx HD2300/HD2400/HD3400 - lowend */
1348 if (strstr(gl_renderer, "HD 2300")
1349 || strstr(gl_renderer, "HD 2400")
1350 || strstr(gl_renderer, "HD 3470")
1351 || strstr(gl_renderer, "HD 3450")
1352 || strstr(gl_renderer, "HD 3430")
1353 || strstr(gl_renderer, "HD 3400"))
1355 *vidmem = 128; /* HD2300 uses at least 128MB, HD2400 uses 256MB */
1356 return CARD_ATI_RADEON_HD2300;
1359 /* Radeon R6xx/R7xx integrated */
1360 if (strstr(gl_renderer, "HD 3100")
1361 || strstr(gl_renderer, "HD 3200")
1362 || strstr(gl_renderer, "HD 3300"))
1364 *vidmem = 128; /* 128MB */
1365 return CARD_ATI_RADEON_HD3200;
1369 if (strstr(gl_renderer, "X1600")
1370 || strstr(gl_renderer, "X1650")
1371 || strstr(gl_renderer, "X1800")
1372 || strstr(gl_renderer, "X1900")
1373 || strstr(gl_renderer, "X1950"))
1375 *vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
1376 return CARD_ATI_RADEON_X1600;
1379 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
1380 if (strstr(gl_renderer, "X700")
1381 || strstr(gl_renderer, "X800")
1382 || strstr(gl_renderer, "X850")
1383 || strstr(gl_renderer, "X1300")
1384 || strstr(gl_renderer, "X1400")
1385 || strstr(gl_renderer, "X1450")
1386 || strstr(gl_renderer, "X1550"))
1388 *vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
1389 return CARD_ATI_RADEON_X700;
1392 /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400MHz */
1393 if (strstr(gl_renderer, "Radeon Xpress"))
1395 *vidmem = 64; /* Shared RAM, BIOS configurable, 64-256M */
1396 return CARD_ATI_RADEON_XPRESS_200M;
1400 *vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
1401 return CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
1404 if (WINE_D3D8_CAPABLE(gl_info))
1406 *vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
1407 return CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
1410 if (WINE_D3D7_CAPABLE(gl_info))
1412 *vidmem = 32; /* There are models with up to 64MB */
1413 return CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
1416 *vidmem = 16; /* There are 16-32MB models */
1417 return CARD_ATI_RAGE_128PRO;
1420 if (strstr(gl_renderer, "X3100"))
1422 /* MacOS calls the card GMA X3100, Google findings also suggest the name GM965 */
1424 return CARD_INTEL_X3100;
1427 if (strstr(gl_renderer, "GMA 950") || strstr(gl_renderer, "945GM"))
1429 /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */
1431 return CARD_INTEL_I945GM;
1434 if (strstr(gl_renderer, "915GM")) return CARD_INTEL_I915GM;
1435 if (strstr(gl_renderer, "915G")) return CARD_INTEL_I915G;
1436 if (strstr(gl_renderer, "865G")) return CARD_INTEL_I865G;
1437 if (strstr(gl_renderer, "855G")) return CARD_INTEL_I855G;
1438 if (strstr(gl_renderer, "830G")) return CARD_INTEL_I830G;
1439 return CARD_INTEL_I915G;
1444 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice
1445 * for Nvidia was because the hardware and drivers they make are of good quality. This makes
1446 * them a good generic choice. */
1447 *vendor = VENDOR_NVIDIA;
1448 if (WINE_D3D9_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCEFX_5600;
1449 if (WINE_D3D8_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE3;
1450 if (WINE_D3D7_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE;
1451 if (WINE_D3D6_CAPABLE(gl_info)) return CARD_NVIDIA_RIVA_TNT;
1452 return CARD_NVIDIA_RIVA_128;
1456 /* Context activation is done by the caller. */
1457 static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_gl_info *gl_info)
1459 const char *GL_Extensions = NULL;
1460 const char *WGL_Extensions = NULL;
1461 const char *gl_string = NULL;
1463 GLfloat gl_floatv[2];
1466 unsigned int vidmem=0;
1471 TRACE_(d3d_caps)("(%p)\n", gl_info);
1475 gl_string = (const char *)glGetString(GL_RENDERER);
1476 TRACE_(d3d_caps)("GL_RENDERER: %s.\n", debugstr_a(gl_string));
1479 ERR_(d3d_caps)("Received a NULL GL_RENDERER.\n");
1483 len = strlen(gl_string) + 1;
1484 gl_renderer = HeapAlloc(GetProcessHeap(), 0, len);
1487 ERR_(d3d_caps)("Failed to allocate gl_renderer memory.\n");
1490 memcpy(gl_renderer, gl_string, len);
1492 gl_string = (const char *)glGetString(GL_VENDOR);
1493 TRACE_(d3d_caps)("GL_VENDOR: %s.\n", debugstr_a(gl_string));
1496 ERR_(d3d_caps)("Received a NULL GL_VENDOR.\n");
1497 HeapFree(GetProcessHeap(), 0, gl_renderer);
1500 gl_info->gl_vendor = wined3d_guess_vendor(gl_string, gl_renderer);
1501 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
1503 /* Parse the GL_VERSION field into major and minor information */
1504 gl_string = (const char *)glGetString(GL_VERSION);
1505 TRACE_(d3d_caps)("GL_VERSION: %s.\n", debugstr_a(gl_string));
1508 ERR_(d3d_caps)("Received a NULL GL_VERSION.\n");
1509 HeapFree(GetProcessHeap(), 0, gl_renderer);
1512 gl_version = wined3d_parse_gl_version(gl_string);
1515 * Initialize openGL extension related variables
1516 * with Default values
1518 memset(gl_info->supported, 0, sizeof(gl_info->supported));
1519 gl_info->max_buffers = 1;
1520 gl_info->max_textures = 1;
1521 gl_info->max_texture_stages = 1;
1522 gl_info->max_fragment_samplers = 1;
1523 gl_info->max_vertex_samplers = 0;
1524 gl_info->max_combined_samplers = gl_info->max_fragment_samplers + gl_info->max_vertex_samplers;
1525 gl_info->max_sampler_stages = 1;
1526 gl_info->ps_arb_max_temps = 0;
1527 gl_info->ps_arb_max_instructions = 0;
1528 gl_info->vs_arb_max_temps = 0;
1529 gl_info->vs_arb_max_instructions = 0;
1530 gl_info->vs_glsl_constantsF = 0;
1531 gl_info->ps_glsl_constantsF = 0;
1532 gl_info->vs_arb_constantsF = 0;
1533 gl_info->ps_arb_constantsF = 0;
1534 gl_info->ps_arb_max_local_constants = 0;
1536 /* Retrieve opengl defaults */
1537 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
1538 gl_info->max_clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
1539 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
1541 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
1542 gl_info->max_lights = gl_max;
1543 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
1545 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
1546 gl_info->max_texture_size = gl_max;
1547 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
1549 glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, gl_floatv);
1550 gl_info->max_pointsizemin = gl_floatv[0];
1551 gl_info->max_pointsize = gl_floatv[1];
1552 TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
1554 /* Parse the gl supported features, in theory enabling parts of our code appropriately. */
1555 GL_Extensions = (const char *)glGetString(GL_EXTENSIONS);
1558 ERR_(d3d_caps)("Received a NULL GL_EXTENSIONS.\n");
1559 HeapFree(GetProcessHeap(), 0, gl_renderer);
1563 TRACE_(d3d_caps)("GL_Extensions reported:\n");
1565 gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
1567 while (*GL_Extensions)
1570 char current_ext[256];
1572 while (isspace(*GL_Extensions)) ++GL_Extensions;
1573 start = GL_Extensions;
1574 while (!isspace(*GL_Extensions) && *GL_Extensions) ++GL_Extensions;
1576 len = GL_Extensions - start;
1577 if (!len || len >= sizeof(current_ext)) continue;
1579 memcpy(current_ext, start, len);
1580 current_ext[len] = '\0';
1581 TRACE_(d3d_caps)("- %s\n", debugstr_a(current_ext));
1583 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i)
1585 if (!strcmp(current_ext, EXTENSION_MAP[i].extension_string))
1587 TRACE_(d3d_caps)(" FOUND: %s support.\n", EXTENSION_MAP[i].extension_string);
1588 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
1596 /* Now work out what GL support this card really has */
1597 #define USE_GL_FUNC(type, pfn, ext, replace) \
1599 DWORD ver = ver_for_ext(ext); \
1600 if (gl_info->supported[ext]) gl_info->pfn = (type)pwglGetProcAddress(#pfn); \
1601 else if (ver && ver <= gl_version) gl_info->pfn = (type)pwglGetProcAddress(#replace); \
1602 else gl_info->pfn = NULL; \
1607 #define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type)pwglGetProcAddress(#pfn);
1613 /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
1614 * loading the functions, otherwise the code above will load the extension entry points instead of the
1615 * core functions, which may not work. */
1616 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i)
1618 if (!gl_info->supported[EXTENSION_MAP[i].extension]
1619 && EXTENSION_MAP[i].version <= gl_version && EXTENSION_MAP[i].version)
1621 TRACE_(d3d_caps)(" GL CORE: %s support.\n", EXTENSION_MAP[i].extension_string);
1622 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
1626 if (gl_info->supported[APPLE_FENCE])
1628 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
1629 * The apple extension interacts with some other apple exts. Disable the NV
1630 * extension if the apple one is support to prevent confusion in other parts
1632 gl_info->supported[NV_FENCE] = FALSE;
1634 if (gl_info->supported[APPLE_FLOAT_PIXELS])
1636 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
1638 * The enums are the same:
1639 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881A
1640 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881B
1641 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
1642 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
1643 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140B
1645 if (!gl_info->supported[ARB_TEXTURE_FLOAT])
1647 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels.\n");
1648 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
1650 if (!gl_info->supported[ARB_HALF_FLOAT_PIXEL])
1652 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels.\n");
1653 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
1656 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
1658 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support.\n");
1659 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
1661 if (gl_info->supported[NV_TEXTURE_SHADER2])
1663 if (gl_info->supported[NV_REGISTER_COMBINERS])
1665 /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
1666 * are supported. The nv extensions provide the same functionality as the
1667 * ATI one, and a bit more(signed pixelformats). */
1668 gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
1671 if (gl_info->supported[ARB_DRAW_BUFFERS])
1673 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
1674 gl_info->max_buffers = gl_max;
1675 TRACE_(d3d_caps)("Max draw buffers: %u.\n", gl_max);
1677 if (gl_info->supported[ARB_MULTITEXTURE])
1679 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
1680 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
1681 TRACE_(d3d_caps)("Max textures: %d.\n", gl_info->max_textures);
1683 if (gl_info->supported[NV_REGISTER_COMBINERS])
1686 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &tmp);
1687 gl_info->max_texture_stages = min(MAX_TEXTURES, tmp);
1691 gl_info->max_texture_stages = min(MAX_TEXTURES, gl_max);
1693 TRACE_(d3d_caps)("Max texture stages: %d.\n", gl_info->max_texture_stages);
1695 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
1698 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
1699 gl_info->max_fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
1703 gl_info->max_fragment_samplers = max(gl_info->max_fragment_samplers, gl_max);
1705 TRACE_(d3d_caps)("Max fragment samplers: %d.\n", gl_info->max_fragment_samplers);
1707 if (gl_info->supported[ARB_VERTEX_SHADER])
1710 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
1711 gl_info->max_vertex_samplers = tmp;
1712 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
1713 gl_info->max_combined_samplers = tmp;
1715 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
1716 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
1717 * an issue because then the sampler setup only depends on the two shaders. If a pixel
1718 * shader is used with fixed function vertex processing we're fine too because fixed function
1719 * vertex processing doesn't use any samplers. If fixed function fragment processing is
1720 * used we have to make sure that all vertex sampler setups are valid together with all
1721 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
1722 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
1723 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
1724 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
1725 * a fixed function pipeline anymore.
1727 * So this is just a check to check that our assumption holds true. If not, write a warning
1728 * and reduce the number of vertex samplers or probably disable vertex texture fetch. */
1729 if (gl_info->max_vertex_samplers && gl_info->max_combined_samplers < 12
1730 && MAX_TEXTURES + gl_info->max_vertex_samplers > gl_info->max_combined_samplers)
1732 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers.\n",
1733 gl_info->max_vertex_samplers, gl_info->max_combined_samplers);
1734 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers.\n");
1735 if (gl_info->max_combined_samplers > MAX_TEXTURES)
1736 gl_info->max_vertex_samplers = gl_info->max_combined_samplers - MAX_TEXTURES;
1738 gl_info->max_vertex_samplers = 0;
1743 gl_info->max_combined_samplers = gl_info->max_fragment_samplers;
1745 TRACE_(d3d_caps)("Max vertex samplers: %u.\n", gl_info->max_vertex_samplers);
1746 TRACE_(d3d_caps)("Max combined samplers: %u.\n", gl_info->max_combined_samplers);
1748 if (gl_info->supported[ARB_VERTEX_BLEND])
1750 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
1751 gl_info->max_blends = gl_max;
1752 TRACE_(d3d_caps)("Max blends: %u.\n", gl_info->max_blends);
1754 if (gl_info->supported[EXT_TEXTURE3D])
1756 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
1757 gl_info->max_texture3d_size = gl_max;
1758 TRACE_(d3d_caps)("Max texture3D size: %d.\n", gl_info->max_texture3d_size);
1760 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
1762 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
1763 gl_info->max_anisotropy = gl_max;
1764 TRACE_(d3d_caps)("Max anisotropy: %d.\n", gl_info->max_anisotropy);
1766 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
1768 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
1769 gl_info->ps_arb_constantsF = gl_max;
1770 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d.\n", gl_info->ps_arb_constantsF);
1771 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
1772 gl_info->ps_arb_max_temps = gl_max;
1773 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d.\n", gl_info->ps_arb_max_temps);
1774 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
1775 gl_info->ps_arb_max_instructions = gl_max;
1776 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d.\n", gl_info->ps_arb_max_instructions);
1777 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, &gl_max));
1778 gl_info->ps_arb_max_local_constants = gl_max;
1779 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM local parameters: %d.\n", gl_info->ps_arb_max_instructions);
1781 if (gl_info->supported[ARB_VERTEX_PROGRAM])
1783 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
1784 gl_info->vs_arb_constantsF = gl_max;
1785 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d.\n", gl_info->vs_arb_constantsF);
1786 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
1787 gl_info->vs_arb_max_temps = gl_max;
1788 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d.\n", gl_info->vs_arb_max_temps);
1789 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
1790 gl_info->vs_arb_max_instructions = gl_max;
1791 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d.\n", gl_info->vs_arb_max_instructions);
1793 if (test_arb_vs_offset_limit(gl_info)) gl_info->quirks |= WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT;
1795 if (gl_info->supported[ARB_VERTEX_SHADER])
1797 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
1798 gl_info->vs_glsl_constantsF = gl_max / 4;
1799 TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u.\n", gl_info->vs_glsl_constantsF);
1801 if (gl_info->supported[ARB_FRAGMENT_SHADER])
1803 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
1804 gl_info->ps_glsl_constantsF = gl_max / 4;
1805 TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u.\n", gl_info->ps_glsl_constantsF);
1806 glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
1807 gl_info->max_glsl_varyings = gl_max;
1808 TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings).\n", gl_max, gl_max / 4);
1810 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT])
1812 glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->max_shininess);
1816 gl_info->max_shininess = 128.0f;
1818 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
1820 /* If we have full NP2 texture support, disable
1821 * GL_ARB_texture_rectangle because we will never use it.
1822 * This saves a few redundant glDisable calls. */
1823 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
1825 if (gl_info->supported[ATI_FRAGMENT_SHADER])
1827 /* Disable NV_register_combiners and fragment shader if this is supported.
1828 * generally the NV extensions are preferred over the ATI ones, and this
1829 * extension is disabled if register_combiners and texture_shader2 are both
1830 * supported. So we reach this place only if we have incomplete NV dxlevel 8
1831 * fragment processing support. */
1832 gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
1833 gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
1834 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
1835 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
1836 gl_info->supported[NV_TEXTURE_SHADER3] = FALSE;
1838 if (gl_info->supported[NV_HALF_FLOAT])
1840 /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float. */
1841 gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE;
1843 if (gl_info->supported[ARB_POINT_SPRITE])
1845 gl_info->max_point_sprite_units = gl_info->max_textures;
1849 gl_info->max_point_sprite_units = 0;
1851 checkGLcall("extension detection");
1855 /* In some cases the number of texture stages can be larger than the number
1856 * of samplers. The GF4 for example can use only 2 samplers (no fragment
1857 * shaders), but 8 texture stages (register combiners). */
1858 gl_info->max_sampler_stages = max(gl_info->max_fragment_samplers, gl_info->max_texture_stages);
1860 /* We can only use ORM_FBO when the hardware supports it. */
1861 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && !gl_info->supported[EXT_FRAMEBUFFER_OBJECT]) {
1862 WARN_(d3d_caps)("GL_EXT_framebuffer_object not supported, falling back to backbuffer offscreen rendering mode.\n");
1863 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
1866 /* MRTs are currently only supported when FBOs are used. */
1867 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) {
1868 gl_info->max_buffers = 1;
1871 gl_info->gl_card = wined3d_guess_card(gl_info, gl_renderer, &gl_info->gl_vendor, &vidmem);
1872 TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card);
1874 /* If we have an estimate use it, else default to 64MB; */
1876 gl_info->vidmem = vidmem*1024*1024; /* convert from MBs to bytes */
1878 gl_info->vidmem = WINE_DEFAULT_VIDMEM;
1880 /* Load all the lookup tables */
1881 for (i = 0; i < MAX_LOOKUPS; i++) {
1882 stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
1885 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
1886 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
1887 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1888 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1889 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1890 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1891 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
1892 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
1893 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
1894 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
1896 /* Make sure there's an active HDC else the WGL extensions will fail */
1897 hdc = pwglGetCurrentDC();
1899 /* Not all GL drivers might offer WGL extensions e.g. VirtualBox */
1900 if(GL_EXTCALL(wglGetExtensionsStringARB))
1901 WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc));
1903 if (NULL == WGL_Extensions) {
1904 ERR(" WGL_Extensions returns NULL\n");
1906 TRACE_(d3d_caps)("WGL_Extensions reported:\n");
1907 while (*WGL_Extensions != 0x00) {
1911 while (isspace(*WGL_Extensions)) WGL_Extensions++;
1912 Start = WGL_Extensions;
1913 while (!isspace(*WGL_Extensions) && *WGL_Extensions != 0x00) {
1917 len = WGL_Extensions - Start;
1918 if (len == 0 || len >= sizeof(ThisExtn))
1921 memcpy(ThisExtn, Start, len);
1922 ThisExtn[len] = '\0';
1923 TRACE_(d3d_caps)("- %s\n", debugstr_a(ThisExtn));
1925 if (!strcmp(ThisExtn, "WGL_ARB_pbuffer")) {
1926 gl_info->supported[WGL_ARB_PBUFFER] = TRUE;
1927 TRACE_(d3d_caps)("FOUND: WGL_ARB_pbuffer support\n");
1929 if (!strcmp(ThisExtn, "WGL_ARB_pixel_format")) {
1930 gl_info->supported[WGL_ARB_PIXEL_FORMAT] = TRUE;
1931 TRACE_(d3d_caps)("FOUND: WGL_ARB_pixel_format support\n");
1933 if (!strcmp(ThisExtn, "WGL_WINE_pixel_format_passthrough")) {
1934 gl_info->supported[WGL_WINE_PIXEL_FORMAT_PASSTHROUGH] = TRUE;
1935 TRACE_(d3d_caps)("FOUND: WGL_WINE_pixel_format_passthrough support\n");
1941 fixup_extensions(gl_info, gl_renderer);
1942 add_gl_compat_wrappers(gl_info);
1944 HeapFree(GetProcessHeap(), 0, gl_renderer);
1948 /**********************************************************
1949 * IWineD3D implementation follows
1950 **********************************************************/
1952 static UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
1953 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1955 TRACE_(d3d_caps)("(%p): Reporting %u adapters\n", This, This->adapter_count);
1957 return This->adapter_count;
1960 static HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
1961 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1962 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
1966 static HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
1967 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1969 TRACE_(d3d_caps)("(%p)->(%d)\n", This, Adapter);
1971 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
1975 return MonitorFromPoint(This->adapters[Adapter].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
1978 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
1979 of the same bpp but different resolutions */
1981 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1982 static UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
1983 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1984 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
1986 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1990 /* TODO: Store modes per adapter and read it from the adapter structure */
1991 if (Adapter == 0) { /* Display */
1996 memset(&mode, 0, sizeof(mode));
1997 mode.dmSize = sizeof(mode);
1999 while (EnumDisplaySettingsExW(NULL, j, &mode, 0))
2004 case WINED3DFMT_UNKNOWN:
2005 /* This is for D3D8, do not enumerate P8 here */
2006 if (mode.dmBitsPerPel == 32 || mode.dmBitsPerPel == 16) ++i;
2009 case WINED3DFMT_X8R8G8B8:
2010 if (mode.dmBitsPerPel == 32) ++i;
2013 case WINED3DFMT_R5G6B5:
2014 if (mode.dmBitsPerPel == 16) ++i;
2018 if (mode.dmBitsPerPel == 8) ++i;
2022 /* Skip other modes as they do not match the requested format */
2027 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
2030 FIXME_(d3d_caps)("Adapter not primary display\n");
2035 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
2036 static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, WINED3DDISPLAYMODE* pMode) {
2037 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2038 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
2040 /* Validate the parameters as much as possible */
2041 if (NULL == pMode ||
2042 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
2043 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
2044 return WINED3DERR_INVALIDCALL;
2047 /* TODO: Store modes per adapter and read it from the adapter structure */
2055 ZeroMemory(&DevModeW, sizeof(DevModeW));
2056 DevModeW.dmSize = sizeof(DevModeW);
2058 /* If we are filtering to a specific format (D3D9), then need to skip
2059 all unrelated modes, but if mode is irrelevant (D3D8), then we can
2060 just count through the ones with valid bit depths */
2061 while ((i<=Mode) && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0)) {
2064 case WINED3DFMT_UNKNOWN:
2065 /* This is D3D8. Do not enumerate P8 here */
2066 if (DevModeW.dmBitsPerPel == 32 ||
2067 DevModeW.dmBitsPerPel == 16) i++;
2069 case WINED3DFMT_X8R8G8B8:
2070 if (DevModeW.dmBitsPerPel == 32) i++;
2072 case WINED3DFMT_R5G6B5:
2073 if (DevModeW.dmBitsPerPel == 16) i++;
2076 if (DevModeW.dmBitsPerPel == 8) i++;
2079 /* Modes that don't match what we support can get an early-out */
2080 TRACE_(d3d_caps)("Searching for %s, returning D3DERR_INVALIDCALL\n", debug_d3dformat(Format));
2081 return WINED3DERR_INVALIDCALL;
2086 TRACE_(d3d_caps)("No modes found for format (%x - %s)\n", Format, debug_d3dformat(Format));
2087 return WINED3DERR_INVALIDCALL;
2091 /* Now get the display mode via the calculated index */
2092 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0)) {
2093 pMode->Width = DevModeW.dmPelsWidth;
2094 pMode->Height = DevModeW.dmPelsHeight;
2095 pMode->RefreshRate = DEFAULT_REFRESH_RATE;
2096 if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
2097 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
2099 if (Format == WINED3DFMT_UNKNOWN) {
2100 pMode->Format = pixelformat_for_depth(DevModeW.dmBitsPerPel);
2102 pMode->Format = Format;
2105 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
2106 return WINED3DERR_INVALIDCALL;
2109 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
2110 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format),
2111 DevModeW.dmBitsPerPel);
2116 FIXME_(d3d_caps)("Adapter not primary display\n");
2122 static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, WINED3DDISPLAYMODE* pMode) {
2123 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2124 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
2126 if (NULL == pMode ||
2127 Adapter >= IWineD3D_GetAdapterCount(iface)) {
2128 return WINED3DERR_INVALIDCALL;
2131 if (Adapter == 0) { /* Display */
2135 ZeroMemory(&DevModeW, sizeof(DevModeW));
2136 DevModeW.dmSize = sizeof(DevModeW);
2138 EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &DevModeW, 0);
2139 pMode->Width = DevModeW.dmPelsWidth;
2140 pMode->Height = DevModeW.dmPelsHeight;
2141 bpp = DevModeW.dmBitsPerPel;
2142 pMode->RefreshRate = DEFAULT_REFRESH_RATE;
2143 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
2145 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
2148 pMode->Format = pixelformat_for_depth(bpp);
2150 FIXME_(d3d_caps)("Adapter not primary display\n");
2153 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
2154 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
2158 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
2159 and fields being inserted in the middle, a new structure is used in place */
2160 static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
2161 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
2162 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2165 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %x, pId=%p)\n", This, Adapter, Flags, pIdentifier);
2167 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2168 return WINED3DERR_INVALIDCALL;
2171 /* Return the information requested */
2172 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
2174 if (pIdentifier->driver_size)
2176 len = min(strlen(This->adapters[Adapter].driver), pIdentifier->driver_size - 1);
2177 memcpy(pIdentifier->driver, This->adapters[Adapter].driver, len);
2178 pIdentifier->driver[len] = '\0';
2181 if (pIdentifier->description_size)
2183 const char *description;
2185 if (This->adapters[Adapter].gl_info.driver_description)
2186 description = This->adapters[Adapter].gl_info.driver_description;
2188 description = This->adapters[Adapter].description;
2190 len = min(strlen(description), pIdentifier->description_size - 1);
2191 memcpy(pIdentifier->description, description, len);
2192 pIdentifier->description[len] = '\0';
2195 /* Note that d3d8 doesn't supply a device name. */
2196 if (pIdentifier->device_name_size)
2198 static const char *device_name = "\\\\.\\DISPLAY1"; /* FIXME: May depend on desktop? */
2200 len = strlen(device_name);
2201 if (len >= pIdentifier->device_name_size)
2203 ERR("Device name size too small.\n");
2204 return WINED3DERR_INVALIDCALL;
2207 memcpy(pIdentifier->device_name, device_name, len);
2208 pIdentifier->device_name[len] = '\0';
2211 pIdentifier->driver_version.u.HighPart = This->adapters[Adapter].gl_info.driver_version_hipart;
2212 pIdentifier->driver_version.u.LowPart = This->adapters[Adapter].gl_info.driver_version;
2213 pIdentifier->vendor_id = This->adapters[Adapter].gl_info.gl_vendor;
2214 pIdentifier->device_id = This->adapters[Adapter].gl_info.gl_card;
2215 pIdentifier->subsystem_id = 0;
2216 pIdentifier->revision = 0;
2217 memcpy(&pIdentifier->device_identifier, &IID_D3DDEVICE_D3DUID, sizeof(pIdentifier->device_identifier));
2219 if(wined3d_settings.pci_device_id != PCI_DEVICE_NONE)
2221 TRACE_(d3d_caps)("Overriding pci device id with: %x\n", wined3d_settings.pci_device_id);
2222 pIdentifier->device_id = wined3d_settings.pci_device_id;
2225 if(wined3d_settings.pci_vendor_id != PCI_VENDOR_NONE)
2227 TRACE_(d3d_caps)("Overriding pci vendor id with: %x\n", wined3d_settings.pci_vendor_id);
2228 pIdentifier->vendor_id = wined3d_settings.pci_vendor_id;
2231 pIdentifier->whql_level = (Flags & WINED3DENUM_NO_WHQL_LEVEL) ? 0 : 1;
2236 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const struct wined3d_gl_info *gl_info,
2237 const WineD3D_PixelFormat *cfg, const struct GlPixelFormatDesc *format_desc)
2239 short redSize, greenSize, blueSize, alphaSize, colorBits;
2244 if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */
2245 if (!getColorBits(format_desc, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
2247 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(format_desc->format));
2251 if(cfg->redSize < redSize)
2254 if(cfg->greenSize < greenSize)
2257 if(cfg->blueSize < blueSize)
2260 if(cfg->alphaSize < alphaSize)
2264 } else if(cfg->iPixelType == WGL_TYPE_RGBA_FLOAT_ARB) { /* Float RGBA formats; TODO: WGL_NV_float_buffer */
2265 if (format_desc->format == WINED3DFMT_R16_FLOAT)
2266 return (cfg->redSize == 16 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
2267 if (format_desc->format == WINED3DFMT_R16G16_FLOAT)
2268 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 0 && cfg->alphaSize == 0);
2269 if (format_desc->format == WINED3DFMT_R16G16B16A16_FLOAT)
2270 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 16 && cfg->alphaSize == 16);
2271 if (format_desc->format == WINED3DFMT_R32_FLOAT)
2272 return (cfg->redSize == 32 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
2273 if (format_desc->format == WINED3DFMT_R32G32_FLOAT)
2274 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 0 && cfg->alphaSize == 0);
2275 if (format_desc->format == WINED3DFMT_R32G32B32A32_FLOAT)
2276 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 32 && cfg->alphaSize == 32);
2278 /* Probably a color index mode */
2285 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const struct wined3d_gl_info *gl_info,
2286 const WineD3D_PixelFormat *cfg, const struct GlPixelFormatDesc *format_desc)
2288 short depthSize, stencilSize;
2289 BOOL lockable = FALSE;
2294 if (!getDepthStencilBits(format_desc, &depthSize, &stencilSize))
2296 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(format_desc->format));
2300 if ((format_desc->format == WINED3DFMT_D16_LOCKABLE) || (format_desc->format == WINED3DFMT_D32F_LOCKABLE))
2303 /* On some modern cards like the Geforce8/9 GLX doesn't offer some dephthstencil formats which D3D9 reports.
2304 * We can safely report 'compatible' formats (e.g. D24 can be used for D16) as long as we aren't dealing with
2305 * a lockable format. This also helps D3D <= 7 as they expect D16 which isn't offered without this on Geforce8 cards. */
2306 if(!(cfg->depthSize == depthSize || (!lockable && cfg->depthSize > depthSize)))
2309 /* Some cards like Intel i915 ones only offer D24S8 but lots of games also need a format without stencil, so
2310 * allow more stencil bits than requested. */
2311 if(cfg->stencilSize < stencilSize)
2317 static HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2318 WINED3DFORMAT AdapterFormat,
2319 WINED3DFORMAT RenderTargetFormat,
2320 WINED3DFORMAT DepthStencilFormat) {
2321 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2323 const WineD3D_PixelFormat *cfgs;
2324 const struct WineD3DAdapter *adapter;
2325 const struct GlPixelFormatDesc *rt_format_desc;
2326 const struct GlPixelFormatDesc *ds_format_desc;
2329 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
2331 DeviceType, debug_d3ddevicetype(DeviceType),
2332 AdapterFormat, debug_d3dformat(AdapterFormat),
2333 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
2334 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
2336 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2337 TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning WINED3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
2338 return WINED3DERR_INVALIDCALL;
2341 adapter = &This->adapters[Adapter];
2342 rt_format_desc = getFormatDescEntry(RenderTargetFormat, &adapter->gl_info);
2343 ds_format_desc = getFormatDescEntry(DepthStencilFormat, &adapter->gl_info);
2344 cfgs = adapter->cfgs;
2345 nCfgs = adapter->nCfgs;
2346 for (it = 0; it < nCfgs; ++it) {
2347 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, &cfgs[it], rt_format_desc))
2349 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[it], ds_format_desc))
2351 TRACE_(d3d_caps)("(%p) : Formats matched\n", This);
2356 WARN_(d3d_caps)("unsupported format pair: %s and %s\n", debug_d3dformat(RenderTargetFormat), debug_d3dformat(DepthStencilFormat));
2358 return WINED3DERR_NOTAVAILABLE;
2361 static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2362 WINED3DFORMAT SurfaceFormat,
2363 BOOL Windowed, WINED3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
2365 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2366 const struct GlPixelFormatDesc *glDesc;
2367 const struct WineD3DAdapter *adapter;
2369 TRACE_(d3d_caps)("(%p)-> (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
2372 DeviceType, debug_d3ddevicetype(DeviceType),
2373 SurfaceFormat, debug_d3dformat(SurfaceFormat),
2378 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2379 return WINED3DERR_INVALIDCALL;
2382 /* TODO: handle Windowed, add more quality levels */
2384 if (WINED3DMULTISAMPLE_NONE == MultiSampleType) {
2385 if(pQualityLevels) *pQualityLevels = 1;
2389 /* By default multisampling is disabled right now as it causes issues
2390 * on some Nvidia driver versions and it doesn't work well in combination
2392 if(!wined3d_settings.allow_multisampling)
2393 return WINED3DERR_NOTAVAILABLE;
2395 adapter = &This->adapters[Adapter];
2396 glDesc = getFormatDescEntry(SurfaceFormat, &adapter->gl_info);
2397 if (!glDesc) return WINED3DERR_INVALIDCALL;
2399 if(glDesc->Flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)) {
2401 const WineD3D_PixelFormat *cfgs;
2403 cfgs = adapter->cfgs;
2404 nCfgs = adapter->nCfgs;
2405 for(i=0; i<nCfgs; i++) {
2406 if(cfgs[i].numSamples != MultiSampleType)
2409 if (!IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[i], glDesc))
2412 TRACE("Found iPixelFormat=%d to support MultiSampleType=%d for format %s\n", cfgs[i].iPixelFormat, MultiSampleType, debug_d3dformat(SurfaceFormat));
2415 *pQualityLevels = 1; /* Guess at a value! */
2419 else if(glDesc->Flags & WINED3DFMT_FLAG_RENDERTARGET) {
2420 short redSize, greenSize, blueSize, alphaSize, colorBits;
2422 const WineD3D_PixelFormat *cfgs;
2424 if (!getColorBits(glDesc, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
2426 ERR("Unable to color bits for format %#x, can't check multisampling capability!\n", SurfaceFormat);
2427 return WINED3DERR_NOTAVAILABLE;
2430 cfgs = adapter->cfgs;
2431 nCfgs = adapter->nCfgs;
2432 for(i=0; i<nCfgs; i++) {
2433 if(cfgs[i].numSamples != MultiSampleType)
2435 if(cfgs[i].redSize != redSize)
2437 if(cfgs[i].greenSize != greenSize)
2439 if(cfgs[i].blueSize != blueSize)
2441 if(cfgs[i].alphaSize != alphaSize)
2444 TRACE("Found iPixelFormat=%d to support MultiSampleType=%d for format %s\n", cfgs[i].iPixelFormat, MultiSampleType, debug_d3dformat(SurfaceFormat));
2447 *pQualityLevels = 1; /* Guess at a value! */
2451 return WINED3DERR_NOTAVAILABLE;
2454 static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2455 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
2457 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2458 HRESULT hr = WINED3DERR_NOTAVAILABLE;
2461 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
2464 DeviceType, debug_d3ddevicetype(DeviceType),
2465 DisplayFormat, debug_d3dformat(DisplayFormat),
2466 BackBufferFormat, debug_d3dformat(BackBufferFormat),
2469 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2470 WARN_(d3d_caps)("Adapter >= IWineD3D_GetAdapterCount(iface), returning WINED3DERR_INVALIDCALL\n");
2471 return WINED3DERR_INVALIDCALL;
2474 /* The task of this function is to check whether a certain display / backbuffer format
2475 * combination is available on the given adapter. In fullscreen mode microsoft specified
2476 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
2477 * and display format should match exactly.
2478 * In windowed mode format conversion can occur and this depends on the driver. When format
2479 * conversion is done, this function should nevertheless fail and applications need to use
2480 * CheckDeviceFormatConversion.
2481 * At the moment we assume that fullscreen and windowed have the same capabilities */
2483 /* There are only 4 display formats */
2484 if(!((DisplayFormat == WINED3DFMT_R5G6B5) ||
2485 (DisplayFormat == WINED3DFMT_X1R5G5B5) ||
2486 (DisplayFormat == WINED3DFMT_X8R8G8B8) ||
2487 (DisplayFormat == WINED3DFMT_A2R10G10B10)))
2489 TRACE_(d3d_caps)("Format %s unsupported as display format\n", debug_d3dformat(DisplayFormat));
2490 return WINED3DERR_NOTAVAILABLE;
2493 /* If the requested DisplayFormat is not available, don't continue */
2494 nmodes = IWineD3DImpl_GetAdapterModeCount(iface, Adapter, DisplayFormat);
2496 TRACE_(d3d_caps)("No available modes for display format %s\n", debug_d3dformat(DisplayFormat));
2497 return WINED3DERR_NOTAVAILABLE;
2500 /* Windowed mode allows you to specify WINED3DFMT_UNKNOWN for the backbufferformat, it means 'reuse' the display format for the backbuffer */
2501 if(!Windowed && BackBufferFormat == WINED3DFMT_UNKNOWN) {
2502 TRACE_(d3d_caps)("BackBufferFormat WINED3FMT_UNKNOWN not available in Windowed mode\n");
2503 return WINED3DERR_NOTAVAILABLE;
2506 /* In FULLSCREEN mode R5G6B5 can only be mixed with backbuffer format R5G6B5 */
2507 if( (DisplayFormat == WINED3DFMT_R5G6B5) && (BackBufferFormat != WINED3DFMT_R5G6B5) ) {
2508 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2509 return WINED3DERR_NOTAVAILABLE;
2512 /* In FULLSCREEN mode X1R5G5B5 can only be mixed with backbuffer format *1R5G5B5 */
2513 if( (DisplayFormat == WINED3DFMT_X1R5G5B5) && !((BackBufferFormat == WINED3DFMT_X1R5G5B5) || (BackBufferFormat == WINED3DFMT_A1R5G5B5)) ) {
2514 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2515 return WINED3DERR_NOTAVAILABLE;
2518 /* In FULLSCREEN mode X8R8G8B8 can only be mixed with backbuffer format *8R8G8B8 */
2519 if( (DisplayFormat == WINED3DFMT_X8R8G8B8) && !((BackBufferFormat == WINED3DFMT_X8R8G8B8) || (BackBufferFormat == WINED3DFMT_A8R8G8B8)) ) {
2520 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2521 return WINED3DERR_NOTAVAILABLE;
2524 /* A2R10G10B10 is only allowed in fullscreen mode and it can only be mixed with backbuffer format A2R10G10B10 */
2525 if( (DisplayFormat == WINED3DFMT_A2R10G10B10) && ((BackBufferFormat != WINED3DFMT_A2R10G10B10) || Windowed)) {
2526 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2527 return WINED3DERR_NOTAVAILABLE;
2530 /* Use CheckDeviceFormat to see if the BackBufferFormat is usable with the given DisplayFormat */
2531 hr = IWineD3DImpl_CheckDeviceFormat(iface, Adapter, DeviceType, DisplayFormat, WINED3DUSAGE_RENDERTARGET, WINED3DRTYPE_SURFACE, BackBufferFormat, SURFACE_OPENGL);
2533 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2539 /* Check if we support bumpmapping for a format */
2540 static BOOL CheckBumpMapCapability(struct WineD3DAdapter *adapter,
2541 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
2543 const struct fragment_pipeline *fp;
2545 switch(format_desc->format)
2547 case WINED3DFMT_R8G8_SNORM:
2548 case WINED3DFMT_R16G16_SNORM:
2549 case WINED3DFMT_L6V5U5:
2550 case WINED3DFMT_X8L8V8U8:
2551 case WINED3DFMT_R8G8B8A8_SNORM:
2552 /* Ask the fixed function pipeline implementation if it can deal
2553 * with the conversion. If we've got a GL extension giving native
2554 * support this will be an identity conversion. */
2555 fp = select_fragment_implementation(adapter, DeviceType);
2556 if (fp->color_fixup_supported(format_desc->color_fixup))
2558 TRACE_(d3d_caps)("[OK]\n");
2561 TRACE_(d3d_caps)("[FAILED]\n");
2565 TRACE_(d3d_caps)("[FAILED]\n");
2570 /* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
2571 static BOOL CheckDepthStencilCapability(struct WineD3DAdapter *adapter,
2572 const struct GlPixelFormatDesc *display_format_desc, const struct GlPixelFormatDesc *ds_format_desc)
2576 /* Only allow depth/stencil formats */
2577 if (!(ds_format_desc->depth_size || ds_format_desc->stencil_size)) return FALSE;
2579 /* Walk through all WGL pixel formats to find a match */
2580 for (it = 0; it < adapter->nCfgs; ++it)
2582 WineD3D_PixelFormat *cfg = &adapter->cfgs[it];
2583 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, cfg, display_format_desc))
2585 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, cfg, ds_format_desc))
2595 static BOOL CheckFilterCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2597 /* The flags entry of a format contains the filtering capability */
2598 if (format_desc->Flags & WINED3DFMT_FLAG_FILTERING) return TRUE;
2603 /* Check the render target capabilities of a format */
2604 static BOOL CheckRenderTargetCapability(struct WineD3DAdapter *adapter,
2605 const struct GlPixelFormatDesc *adapter_format_desc, const struct GlPixelFormatDesc *check_format_desc)
2607 /* Filter out non-RT formats */
2608 if (!(check_format_desc->Flags & WINED3DFMT_FLAG_RENDERTARGET)) return FALSE;
2610 if(wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) {
2611 WineD3D_PixelFormat *cfgs = adapter->cfgs;
2613 short AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
2614 short CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
2616 getColorBits(adapter_format_desc, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
2617 getColorBits(check_format_desc, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
2619 /* In backbuffer mode the front and backbuffer share the same WGL pixelformat.
2620 * The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */
2621 if(!((AdapterRed == CheckRed) && (AdapterGreen == CheckGreen) && (AdapterBlue == CheckBlue))) {
2622 TRACE_(d3d_caps)("[FAILED]\n");
2626 /* Check if there is a WGL pixel format matching the requirements, the format should also be window
2627 * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
2628 for (it = 0; it < adapter->nCfgs; ++it)
2630 if (cfgs[it].windowDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info,
2631 &cfgs[it], check_format_desc))
2633 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n",
2634 cfgs[it].iPixelFormat, debug_d3dformat(check_format_desc->format));
2638 } else if(wined3d_settings.offscreen_rendering_mode == ORM_PBUFFER) {
2639 /* We can probably use this function in FBO mode too on some drivers to get some basic indication of the capabilities. */
2640 WineD3D_PixelFormat *cfgs = adapter->cfgs;
2643 /* Check if there is a WGL pixel format matching the requirements, the pixel format should also be usable with pbuffers */
2644 for (it = 0; it < adapter->nCfgs; ++it)
2646 if (cfgs[it].pbufferDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info,
2647 &cfgs[it], check_format_desc))
2649 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n",
2650 cfgs[it].iPixelFormat, debug_d3dformat(check_format_desc->format));
2654 } else if(wined3d_settings.offscreen_rendering_mode == ORM_FBO){
2655 /* For now return TRUE for FBOs until we have some proper checks.
2656 * Note that this function will only be called when the format is around for texturing. */
2662 static BOOL CheckSrgbReadCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2664 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
2666 /* Check for supported sRGB formats (Texture loading and framebuffer) */
2667 if(!GL_SUPPORT(EXT_TEXTURE_SRGB)) {
2668 TRACE_(d3d_caps)("[FAILED] GL_EXT_texture_sRGB not supported\n");
2672 switch (format_desc->format)
2674 case WINED3DFMT_A8R8G8B8:
2675 case WINED3DFMT_X8R8G8B8:
2676 case WINED3DFMT_A4R4G4B4:
2678 case WINED3DFMT_A8L8:
2679 case WINED3DFMT_DXT1:
2680 case WINED3DFMT_DXT2:
2681 case WINED3DFMT_DXT3:
2682 case WINED3DFMT_DXT4:
2683 case WINED3DFMT_DXT5:
2684 TRACE_(d3d_caps)("[OK]\n");
2688 TRACE_(d3d_caps)("[FAILED] Gamma texture format %s not supported.\n", debug_d3dformat(format_desc->format));
2694 static BOOL CheckSrgbWriteCapability(struct WineD3DAdapter *adapter,
2695 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
2697 /* Only offer SRGB writing on X8R8G8B8/A8R8G8B8 when we use ARB or GLSL shaders as we are
2698 * doing the color fixup in shaders.
2699 * Note Windows drivers (at least on the Geforce 8800) also offer this on R5G6B5. */
2700 if ((format_desc->format == WINED3DFMT_X8R8G8B8) || (format_desc->format == WINED3DFMT_A8R8G8B8))
2702 int vs_selected_mode;
2703 int ps_selected_mode;
2704 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
2706 if((ps_selected_mode == SHADER_ARB) || (ps_selected_mode == SHADER_GLSL)) {
2707 TRACE_(d3d_caps)("[OK]\n");
2712 TRACE_(d3d_caps)("[FAILED] - no SRGB writing support on format=%s\n", debug_d3dformat(format_desc->format));
2716 /* Check if a format support blending in combination with pixel shaders */
2717 static BOOL CheckPostPixelShaderBlendingCapability(struct WineD3DAdapter *adapter,
2718 const struct GlPixelFormatDesc *format_desc)
2720 /* The flags entry of a format contains the post pixel shader blending capability */
2721 if (format_desc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING) return TRUE;
2726 static BOOL CheckWrapAndMipCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2728 /* OpenGL supports mipmapping on all formats basically. Wrapping is unsupported,
2729 * but we have to report mipmapping so we cannot reject this flag. Tests show that
2730 * windows reports WRAPANDMIP on unfilterable surfaces as well, apparently to show
2731 * that wrapping is supported. The lack of filtering will sort out the mipmapping
2732 * capability anyway.
2734 * For now lets report this on all formats, but in the future we may want to
2735 * restrict it to some should games need that
2740 /* Check if a texture format is supported on the given adapter */
2741 static BOOL CheckTextureCapability(struct WineD3DAdapter *adapter,
2742 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
2744 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
2745 const shader_backend_t *shader_backend;
2746 const struct fragment_pipeline *fp;
2748 switch (format_desc->format)
2751 * supported: RGB(A) formats
2753 case WINED3DFMT_R8G8B8: /* Enable for dx7, blacklisted for 8 and 9 above */
2754 case WINED3DFMT_A8R8G8B8:
2755 case WINED3DFMT_X8R8G8B8:
2756 case WINED3DFMT_R5G6B5:
2757 case WINED3DFMT_X1R5G5B5:
2758 case WINED3DFMT_A1R5G5B5:
2759 case WINED3DFMT_A4R4G4B4:
2760 case WINED3DFMT_A8_UNORM:
2761 case WINED3DFMT_X4R4G4B4:
2762 case WINED3DFMT_R8G8B8A8_UNORM:
2763 case WINED3DFMT_X8B8G8R8:
2764 case WINED3DFMT_A2R10G10B10:
2765 case WINED3DFMT_R10G10B10A2_UNORM:
2766 case WINED3DFMT_R16G16_UNORM:
2767 TRACE_(d3d_caps)("[OK]\n");
2770 case WINED3DFMT_R3G3B2:
2771 TRACE_(d3d_caps)("[FAILED] - Not supported on Windows\n");
2775 * supported: Palettized
2778 TRACE_(d3d_caps)("[OK]\n");
2780 /* No Windows driver offers A8P8, so don't offer it either */
2781 case WINED3DFMT_A8P8:
2785 * Supported: (Alpha)-Luminance
2788 case WINED3DFMT_A8L8:
2789 case WINED3DFMT_L16:
2790 TRACE_(d3d_caps)("[OK]\n");
2793 /* Not supported on Windows, thus disabled */
2794 case WINED3DFMT_A4L4:
2795 TRACE_(d3d_caps)("[FAILED] - not supported on windows\n");
2799 * Supported: Depth/Stencil formats
2801 case WINED3DFMT_D16_LOCKABLE:
2802 case WINED3DFMT_D16_UNORM:
2803 case WINED3DFMT_D15S1:
2804 case WINED3DFMT_D24X8:
2805 case WINED3DFMT_D24X4S4:
2806 case WINED3DFMT_D24S8:
2807 case WINED3DFMT_D24FS8:
2808 case WINED3DFMT_D32:
2809 case WINED3DFMT_D32F_LOCKABLE:
2813 * Not supported everywhere(depends on GL_ATI_envmap_bumpmap or
2814 * GL_NV_texture_shader). Emulated by shaders
2816 case WINED3DFMT_R8G8_SNORM:
2817 case WINED3DFMT_X8L8V8U8:
2818 case WINED3DFMT_L6V5U5:
2819 case WINED3DFMT_R8G8B8A8_SNORM:
2820 case WINED3DFMT_R16G16_SNORM:
2821 /* Ask the shader backend if it can deal with the conversion. If
2822 * we've got a GL extension giving native support this will be an
2823 * identity conversion. */
2824 shader_backend = select_shader_backend(adapter, DeviceType);
2825 if (shader_backend->shader_color_fixup_supported(format_desc->color_fixup))
2827 TRACE_(d3d_caps)("[OK]\n");
2830 TRACE_(d3d_caps)("[FAILED]\n");
2833 case WINED3DFMT_DXT1:
2834 case WINED3DFMT_DXT2:
2835 case WINED3DFMT_DXT3:
2836 case WINED3DFMT_DXT4:
2837 case WINED3DFMT_DXT5:
2838 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
2839 TRACE_(d3d_caps)("[OK]\n");
2842 TRACE_(d3d_caps)("[FAILED]\n");
2847 * Odd formats - not supported
2849 case WINED3DFMT_VERTEXDATA:
2850 case WINED3DFMT_R16_UINT:
2851 case WINED3DFMT_R32_UINT:
2852 case WINED3DFMT_R16G16B16A16_SNORM:
2853 case WINED3DFMT_A2W10V10U10:
2854 case WINED3DFMT_W11V11U10:
2855 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2859 * WINED3DFMT_CxV8U8: Not supported right now
2861 case WINED3DFMT_CxV8U8:
2862 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2866 case WINED3DFMT_UYVY:
2867 case WINED3DFMT_YUY2:
2868 if(GL_SUPPORT(APPLE_YCBCR_422)) {
2869 TRACE_(d3d_caps)("[OK]\n");
2872 TRACE_(d3d_caps)("[FAILED]\n");
2874 case WINED3DFMT_YV12:
2875 TRACE_(d3d_caps)("[FAILED]\n");
2879 case WINED3DFMT_R16G16B16A16_UNORM:
2880 case WINED3DFMT_A8R3G3B2:
2881 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2884 /* Floating point formats */
2885 case WINED3DFMT_R16_FLOAT:
2886 case WINED3DFMT_R16G16_FLOAT:
2887 case WINED3DFMT_R16G16B16A16_FLOAT:
2888 if(GL_SUPPORT(ARB_TEXTURE_FLOAT) && GL_SUPPORT(ARB_HALF_FLOAT_PIXEL)) {
2889 TRACE_(d3d_caps)("[OK]\n");
2892 TRACE_(d3d_caps)("[FAILED]\n");
2895 case WINED3DFMT_R32_FLOAT:
2896 case WINED3DFMT_R32G32_FLOAT:
2897 case WINED3DFMT_R32G32B32A32_FLOAT:
2898 if (GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2899 TRACE_(d3d_caps)("[OK]\n");
2902 TRACE_(d3d_caps)("[FAILED]\n");
2905 /* ATI instancing hack: Although ATI cards do not support Shader Model 3.0, they support
2906 * instancing. To query if the card supports instancing CheckDeviceFormat with the special format
2907 * MAKEFOURCC('I','N','S','T') is used. Should a (broken) app check for this provide a proper return value.
2908 * We can do instancing with all shader versions, but we need vertex shaders.
2910 * Additionally applications have to set the D3DRS_POINTSIZE render state to MAKEFOURCC('I','N','S','T') once
2911 * to enable instancing. WineD3D doesn't need that and just ignores it.
2913 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows.
2915 case WINEMAKEFOURCC('I','N','S','T'):
2916 TRACE("ATI Instancing check hack\n");
2917 if(GL_SUPPORT(ARB_VERTEX_PROGRAM) || GL_SUPPORT(ARB_VERTEX_SHADER)) {
2918 TRACE_(d3d_caps)("[OK]\n");
2921 TRACE_(d3d_caps)("[FAILED]\n");
2924 /* Some weird FOURCC formats */
2925 case WINED3DFMT_R8G8_B8G8:
2926 case WINED3DFMT_G8R8_G8B8:
2927 case WINED3DFMT_MULTI2_ARGB8:
2928 TRACE_(d3d_caps)("[FAILED]\n");
2931 /* Vendor specific formats */
2932 case WINED3DFMT_ATI2N:
2933 if(GL_SUPPORT(ATI_TEXTURE_COMPRESSION_3DC) || GL_SUPPORT(EXT_TEXTURE_COMPRESSION_RGTC)) {
2934 shader_backend = select_shader_backend(adapter, DeviceType);
2935 fp = select_fragment_implementation(adapter, DeviceType);
2936 if (shader_backend->shader_color_fixup_supported(format_desc->color_fixup)
2937 && fp->color_fixup_supported(format_desc->color_fixup))
2939 TRACE_(d3d_caps)("[OK]\n");
2943 TRACE_(d3d_caps)("[OK]\n");
2946 TRACE_(d3d_caps)("[FAILED]\n");
2949 case WINED3DFMT_NVHU:
2950 case WINED3DFMT_NVHS:
2951 /* These formats seem to be similar to the HILO formats in GL_NV_texture_shader. NVHU
2952 * is said to be GL_UNSIGNED_HILO16, NVHS GL_SIGNED_HILO16. Rumours say that d3d computes
2953 * a 3rd channel similarly to D3DFMT_CxV8U8(So NVHS could be called D3DFMT_CxV16U16).
2954 * ATI refused to support formats which can easilly be emulated with pixel shaders, so
2955 * Applications have to deal with not having NVHS and NVHU.
2957 TRACE_(d3d_caps)("[FAILED]\n");
2960 case WINED3DFMT_UNKNOWN:
2964 ERR("Unhandled format=%s\n", debug_d3dformat(format_desc->format));
2970 static BOOL CheckSurfaceCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *adapter_format_desc,
2971 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *check_format_desc, WINED3DSURFTYPE SurfaceType)
2973 const struct blit_shader *blitter;
2975 if(SurfaceType == SURFACE_GDI) {
2976 switch(check_format_desc->format)
2978 case WINED3DFMT_R8G8B8:
2979 case WINED3DFMT_A8R8G8B8:
2980 case WINED3DFMT_X8R8G8B8:
2981 case WINED3DFMT_R5G6B5:
2982 case WINED3DFMT_X1R5G5B5:
2983 case WINED3DFMT_A1R5G5B5:
2984 case WINED3DFMT_A4R4G4B4:
2985 case WINED3DFMT_R3G3B2:
2986 case WINED3DFMT_A8_UNORM:
2987 case WINED3DFMT_A8R3G3B2:
2988 case WINED3DFMT_X4R4G4B4:
2989 case WINED3DFMT_R10G10B10A2_UNORM:
2990 case WINED3DFMT_R8G8B8A8_UNORM:
2991 case WINED3DFMT_X8B8G8R8:
2992 case WINED3DFMT_R16G16_UNORM:
2993 case WINED3DFMT_A2R10G10B10:
2994 case WINED3DFMT_R16G16B16A16_UNORM:
2996 TRACE_(d3d_caps)("[OK]\n");
2999 TRACE_(d3d_caps)("[FAILED] - not available on GDI surfaces\n");
3004 /* All format that are supported for textures are supported for surfaces as well */
3005 if (CheckTextureCapability(adapter, DeviceType, check_format_desc)) return TRUE;
3006 /* All depth stencil formats are supported on surfaces */
3007 if (CheckDepthStencilCapability(adapter, adapter_format_desc, check_format_desc)) return TRUE;
3009 /* If opengl can't process the format natively, the blitter may be able to convert it */
3010 blitter = select_blit_implementation(adapter, DeviceType);
3011 if (blitter->color_fixup_supported(check_format_desc->color_fixup))
3013 TRACE_(d3d_caps)("[OK]\n");
3017 /* Reject other formats */
3018 TRACE_(d3d_caps)("[FAILED]\n");
3022 static BOOL CheckVertexTextureCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
3024 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3026 if (!GL_LIMITS(vertex_samplers)) {
3027 TRACE_(d3d_caps)("[FAILED]\n");
3031 switch (format_desc->format)
3033 case WINED3DFMT_R32G32B32A32_FLOAT:
3034 if (!GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
3035 TRACE_(d3d_caps)("[FAILED]\n");
3038 TRACE_(d3d_caps)("[OK]\n");
3042 TRACE_(d3d_caps)("[FAILED]\n");
3048 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
3049 WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat,
3050 WINED3DSURFTYPE SurfaceType) {
3051 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3052 struct WineD3DAdapter *adapter = &This->adapters[Adapter];
3053 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3054 const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(CheckFormat, gl_info);
3055 const struct GlPixelFormatDesc *adapter_format_desc = getFormatDescEntry(AdapterFormat, gl_info);
3056 DWORD UsageCaps = 0;
3058 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%u,%s,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s))\n",
3061 DeviceType, debug_d3ddevicetype(DeviceType),
3062 AdapterFormat, debug_d3dformat(AdapterFormat),
3063 Usage, debug_d3dusage(Usage), debug_d3dusagequery(Usage),
3064 RType, debug_d3dresourcetype(RType),
3065 CheckFormat, debug_d3dformat(CheckFormat));
3067 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
3068 return WINED3DERR_INVALIDCALL;
3071 if(RType == WINED3DRTYPE_CUBETEXTURE) {
3073 if(SurfaceType != SURFACE_OPENGL) {
3074 TRACE("[FAILED]\n");
3075 return WINED3DERR_NOTAVAILABLE;
3078 /* Cubetexture allows:
3079 * - D3DUSAGE_AUTOGENMIPMAP
3080 * - D3DUSAGE_DEPTHSTENCIL
3081 * - D3DUSAGE_DYNAMIC
3082 * - D3DUSAGE_NONSECURE (d3d9ex)
3083 * - D3DUSAGE_RENDERTARGET
3084 * - D3DUSAGE_SOFTWAREPROCESSING
3085 * - D3DUSAGE_QUERY_WRAPANDMIP
3087 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
3088 /* Check if the texture format is around */
3089 if (CheckTextureCapability(adapter, DeviceType, format_desc))
3091 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
3092 /* Check for automatic mipmap generation support */
3093 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
3094 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
3096 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUTOGEN instead of D3D_OK */
3097 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
3101 /* Always report dynamic locking */
3102 if(Usage & WINED3DUSAGE_DYNAMIC)
3103 UsageCaps |= WINED3DUSAGE_DYNAMIC;
3105 if(Usage & WINED3DUSAGE_RENDERTARGET) {
3106 if(CheckRenderTargetCapability(adapter, adapter_format_desc, format_desc))
3108 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
3110 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
3111 return WINED3DERR_NOTAVAILABLE;
3115 /* Always report software processing */
3116 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
3117 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
3119 /* Check QUERY_FILTER support */
3120 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
3121 if (CheckFilterCapability(adapter, format_desc))
3123 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
3125 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
3126 return WINED3DERR_NOTAVAILABLE;
3130 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
3131 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
3132 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
3134 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
3136 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
3137 return WINED3DERR_NOTAVAILABLE;
3141 /* Check QUERY_SRGBREAD support */
3142 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
3143 if (CheckSrgbReadCapability(adapter, format_desc))
3145 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
3147 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
3148 return WINED3DERR_NOTAVAILABLE;
3152 /* Check QUERY_SRGBWRITE support */
3153 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
3154 if (CheckSrgbWriteCapability(adapter, DeviceType, format_desc))
3156 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
3158 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
3159 return WINED3DERR_NOTAVAILABLE;
3163 /* Check QUERY_VERTEXTEXTURE support */
3164 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
3165 if (CheckVertexTextureCapability(adapter, format_desc))
3167 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
3169 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
3170 return WINED3DERR_NOTAVAILABLE;
3174 /* Check QUERY_WRAPANDMIP support */
3175 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
3176 if (CheckWrapAndMipCapability(adapter, format_desc))
3178 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
3180 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
3181 return WINED3DERR_NOTAVAILABLE;
3185 TRACE_(d3d_caps)("[FAILED] - Cube texture format not supported\n");
3186 return WINED3DERR_NOTAVAILABLE;
3189 TRACE_(d3d_caps)("[FAILED] - No cube texture support\n");
3190 return WINED3DERR_NOTAVAILABLE;
3192 } else if(RType == WINED3DRTYPE_SURFACE) {
3194 * - D3DUSAGE_DEPTHSTENCIL
3195 * - D3DUSAGE_NONSECURE (d3d9ex)
3196 * - D3DUSAGE_RENDERTARGET
3199 if (CheckSurfaceCapability(adapter, adapter_format_desc, DeviceType, format_desc, SurfaceType))
3201 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
3202 if (CheckDepthStencilCapability(adapter, adapter_format_desc, format_desc))
3204 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
3206 TRACE_(d3d_caps)("[FAILED] - No depthstencil support\n");
3207 return WINED3DERR_NOTAVAILABLE;
3211 if(Usage & WINED3DUSAGE_RENDERTARGET) {
3212 if (CheckRenderTargetCapability(adapter, adapter_format_desc, format_desc))
3214 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
3216 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
3217 return WINED3DERR_NOTAVAILABLE;
3221 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
3222 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
3223 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
3225 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
3227 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
3228 return WINED3DERR_NOTAVAILABLE;
3232 TRACE_(d3d_caps)("[FAILED] - Not supported for plain surfaces\n");
3233 return WINED3DERR_NOTAVAILABLE;
3236 } else if(RType == WINED3DRTYPE_TEXTURE) {
3238 * - D3DUSAGE_AUTOGENMIPMAP
3239 * - D3DUSAGE_DEPTHSTENCIL
3241 * - D3DUSAGE_DYNAMIC
3242 * - D3DUSAGE_NONSECURE (d3d9ex)
3243 * - D3DUSAGE_RENDERTARGET
3244 * - D3DUSAGE_SOFTWAREPROCESSING
3245 * - D3DUSAGE_TEXTAPI (d3d9ex)
3246 * - D3DUSAGE_QUERY_WRAPANDMIP
3249 if(SurfaceType != SURFACE_OPENGL) {
3250 TRACE("[FAILED]\n");
3251 return WINED3DERR_NOTAVAILABLE;
3254 /* Check if the texture format is around */
3255 if (CheckTextureCapability(adapter, DeviceType, format_desc))
3257 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
3258 /* Check for automatic mipmap generation support */
3259 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
3260 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
3262 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUTOGEN instead of D3D_OK */
3263 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
3267 /* Always report dynamic locking */
3268 if(Usage & WINED3DUSAGE_DYNAMIC)
3269 UsageCaps |= WINED3DUSAGE_DYNAMIC;
3271 if(Usage & WINED3DUSAGE_RENDERTARGET) {
3272 if (CheckRenderTargetCapability(adapter, adapter_format_desc, format_desc))
3274 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
3276 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
3277 return WINED3DERR_NOTAVAILABLE;
3281 /* Always report software processing */
3282 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
3283 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
3285 /* Check QUERY_FILTER support */
3286 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
3287 if (CheckFilterCapability(adapter, format_desc))
3289 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
3291 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
3292 return WINED3DERR_NOTAVAILABLE;
3296 /* Check QUERY_LEGACYBUMPMAP support */
3297 if(Usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP) {
3298 if (CheckBumpMapCapability(adapter, DeviceType, format_desc))
3300 UsageCaps |= WINED3DUSAGE_QUERY_LEGACYBUMPMAP;
3302 TRACE_(d3d_caps)("[FAILED] - No legacy bumpmap support\n");
3303 return WINED3DERR_NOTAVAILABLE;
3307 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
3308 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
3309 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
3311 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
3313 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
3314 return WINED3DERR_NOTAVAILABLE;
3318 /* Check QUERY_SRGBREAD support */
3319 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
3320 if (CheckSrgbReadCapability(adapter, format_desc))
3322 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
3324 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
3325 return WINED3DERR_NOTAVAILABLE;
3329 /* Check QUERY_SRGBWRITE support */
3330 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
3331 if (CheckSrgbWriteCapability(adapter, DeviceType, format_desc))
3333 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
3335 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
3336 return WINED3DERR_NOTAVAILABLE;
3340 /* Check QUERY_VERTEXTEXTURE support */
3341 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
3342 if (CheckVertexTextureCapability(adapter, format_desc))
3344 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
3346 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
3347 return WINED3DERR_NOTAVAILABLE;
3351 /* Check QUERY_WRAPANDMIP support */
3352 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
3353 if (CheckWrapAndMipCapability(adapter, format_desc))
3355 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
3357 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
3358 return WINED3DERR_NOTAVAILABLE;
3362 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
3363 if (CheckDepthStencilCapability(adapter, adapter_format_desc, format_desc))
3365 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
3367 TRACE_(d3d_caps)("[FAILED] - No depth stencil support\n");
3368 return WINED3DERR_NOTAVAILABLE;
3372 TRACE_(d3d_caps)("[FAILED] - Texture format not supported\n");
3373 return WINED3DERR_NOTAVAILABLE;
3375 } else if((RType == WINED3DRTYPE_VOLUME) || (RType == WINED3DRTYPE_VOLUMETEXTURE)) {
3376 /* Volume is to VolumeTexture what Surface is to Texture but its usage caps are not documented.
3377 * Most driver seem to offer (nearly) the same on Volume and VolumeTexture, so do that too.
3379 * Volumetexture allows:
3380 * - D3DUSAGE_DYNAMIC
3381 * - D3DUSAGE_NONSECURE (d3d9ex)
3382 * - D3DUSAGE_SOFTWAREPROCESSING
3383 * - D3DUSAGE_QUERY_WRAPANDMIP
3386 if(SurfaceType != SURFACE_OPENGL) {
3387 TRACE("[FAILED]\n");
3388 return WINED3DERR_NOTAVAILABLE;
3391 /* Check volume texture and volume usage caps */
3392 if(GL_SUPPORT(EXT_TEXTURE3D)) {
3393 if (!CheckTextureCapability(adapter, DeviceType, format_desc))
3395 TRACE_(d3d_caps)("[FAILED] - Format not supported\n");
3396 return WINED3DERR_NOTAVAILABLE;
3399 /* Always report dynamic locking */
3400 if(Usage & WINED3DUSAGE_DYNAMIC)
3401 UsageCaps |= WINED3DUSAGE_DYNAMIC;
3403 /* Always report software processing */
3404 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
3405 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
3407 /* Check QUERY_FILTER support */
3408 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
3409 if (CheckFilterCapability(adapter, format_desc))
3411 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
3413 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
3414 return WINED3DERR_NOTAVAILABLE;
3418 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
3419 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
3420 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
3422 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
3424 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
3425 return WINED3DERR_NOTAVAILABLE;
3429 /* Check QUERY_SRGBREAD support */
3430 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
3431 if (CheckSrgbReadCapability(adapter, format_desc))
3433 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
3435 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
3436 return WINED3DERR_NOTAVAILABLE;
3440 /* Check QUERY_SRGBWRITE support */
3441 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
3442 if (CheckSrgbWriteCapability(adapter, DeviceType, format_desc))
3444 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
3446 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
3447 return WINED3DERR_NOTAVAILABLE;
3451 /* Check QUERY_VERTEXTEXTURE support */
3452 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
3453 if (CheckVertexTextureCapability(adapter, format_desc))
3455 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
3457 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
3458 return WINED3DERR_NOTAVAILABLE;
3462 /* Check QUERY_WRAPANDMIP support */
3463 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
3464 if (CheckWrapAndMipCapability(adapter, format_desc))
3466 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
3468 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
3469 return WINED3DERR_NOTAVAILABLE;
3473 TRACE_(d3d_caps)("[FAILED] - No volume texture support\n");
3474 return WINED3DERR_NOTAVAILABLE;
3477 /* Filter formats that need conversion; For one part, this conversion is unimplemented,
3478 * and volume textures are huge, so it would be a big performance hit. Unless we hit an
3479 * app needing one of those formats, don't advertize them to avoid leading apps into
3480 * temptation. The windows drivers don't support most of those formats on volumes anyway,
3483 switch(CheckFormat) {
3485 case WINED3DFMT_A4L4:
3486 case WINED3DFMT_R32_FLOAT:
3487 case WINED3DFMT_R16_FLOAT:
3488 case WINED3DFMT_X8L8V8U8:
3489 case WINED3DFMT_L6V5U5:
3490 case WINED3DFMT_R16G16_UNORM:
3491 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
3492 return WINED3DERR_NOTAVAILABLE;
3494 case WINED3DFMT_R8G8B8A8_SNORM:
3495 case WINED3DFMT_R16G16_SNORM:
3496 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
3497 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
3498 return WINED3DERR_NOTAVAILABLE;
3502 case WINED3DFMT_R8G8_SNORM:
3503 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
3504 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
3505 return WINED3DERR_NOTAVAILABLE;
3509 case WINED3DFMT_DXT1:
3510 case WINED3DFMT_DXT2:
3511 case WINED3DFMT_DXT3:
3512 case WINED3DFMT_DXT4:
3513 case WINED3DFMT_DXT5:
3514 /* The GL_EXT_texture_compression_s3tc spec requires that loading an s3tc
3515 * compressed texture results in an error. While the D3D refrast does
3516 * support s3tc volumes, at least the nvidia windows driver does not, so
3517 * we're free not to support this format.
3519 TRACE_(d3d_caps)("[FAILED] - DXTn does not support 3D textures\n");
3520 return WINED3DERR_NOTAVAILABLE;
3523 /* Do nothing, continue with checking the format below */
3526 } else if(RType == WINED3DRTYPE_BUFFER){
3527 /* For instance vertexbuffer/indexbuffer aren't supported yet because no Windows drivers seem to offer it */
3528 TRACE_(d3d_caps)("Unhandled resource type D3DRTYPE_INDEXBUFFER / D3DRTYPE_VERTEXBUFFER\n");
3529 return WINED3DERR_NOTAVAILABLE;
3532 /* When the UsageCaps exactly matches Usage return WINED3D_OK except for the situation in which
3533 * WINED3DUSAGE_AUTOGENMIPMAP isn't around, then WINED3DOK_NOAUTOGEN is returned if all the other
3534 * usage flags match. */
3535 if(UsageCaps == Usage) {
3537 } else if((UsageCaps == (Usage & ~WINED3DUSAGE_AUTOGENMIPMAP)) && (Usage & WINED3DUSAGE_AUTOGENMIPMAP)){
3538 return WINED3DOK_NOAUTOGEN;
3540 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);
3541 return WINED3DERR_NOTAVAILABLE;
3545 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
3546 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
3547 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3549 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))\n",
3552 DeviceType, debug_d3ddevicetype(DeviceType),
3553 SourceFormat, debug_d3dformat(SourceFormat),
3554 TargetFormat, debug_d3dformat(TargetFormat));
3558 static const shader_backend_t *select_shader_backend(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType)
3560 const shader_backend_t *ret;
3561 int vs_selected_mode;
3562 int ps_selected_mode;
3564 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
3565 if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) {
3566 ret = &glsl_shader_backend;
3567 } else if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) {
3568 ret = &arb_program_shader_backend;
3570 ret = &none_shader_backend;
3575 static const struct fragment_pipeline *select_fragment_implementation(struct WineD3DAdapter *adapter,
3576 WINED3DDEVTYPE DeviceType)
3578 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3579 int vs_selected_mode;
3580 int ps_selected_mode;
3582 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
3583 if((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
3584 return &arbfp_fragment_pipeline;
3585 } else if(ps_selected_mode == SHADER_ATI) {
3586 return &atifs_fragment_pipeline;
3587 } else if(GL_SUPPORT(NV_REGISTER_COMBINERS) && GL_SUPPORT(NV_TEXTURE_SHADER2)) {
3588 return &nvts_fragment_pipeline;
3589 } else if(GL_SUPPORT(NV_REGISTER_COMBINERS)) {
3590 return &nvrc_fragment_pipeline;
3592 return &ffp_fragment_pipeline;
3596 static const struct blit_shader *select_blit_implementation(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType)
3598 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3599 int vs_selected_mode;
3600 int ps_selected_mode;
3602 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
3603 if((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
3610 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
3611 subset of a D3DCAPS9 structure. However, it has to come via a void *
3612 as the d3d8 interface cannot import the d3d9 header */
3613 static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
3615 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3616 struct WineD3DAdapter *adapter = &This->adapters[Adapter];
3617 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3618 int vs_selected_mode;
3619 int ps_selected_mode;
3620 struct shader_caps shader_caps;
3621 struct fragment_caps fragment_caps;
3622 const shader_backend_t *shader_backend;
3623 const struct fragment_pipeline *frag_pipeline = NULL;
3624 DWORD ckey_caps, blit_caps, fx_caps;
3626 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
3628 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
3629 return WINED3DERR_INVALIDCALL;
3632 select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
3634 /* This function should *not* be modifying GL caps
3635 * TODO: move the functionality where it belongs */
3636 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &adapter->gl_info);
3638 /* ------------------------------------------------
3639 The following fields apply to both d3d8 and d3d9
3640 ------------------------------------------------ */
3641 pCaps->DeviceType = (DeviceType == WINED3DDEVTYPE_HAL) ? WINED3DDEVTYPE_HAL : WINED3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
3642 pCaps->AdapterOrdinal = Adapter;
3645 pCaps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
3646 WINED3DCAPS2_FULLSCREENGAMMA |
3647 WINED3DCAPS2_DYNAMICTEXTURES;
3648 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
3649 pCaps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
3652 pCaps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
3653 WINED3DCAPS3_COPY_TO_VIDMEM |
3654 WINED3DCAPS3_COPY_TO_SYSTEMMEM;
3656 pCaps->PresentationIntervals = WINED3DPRESENT_INTERVAL_IMMEDIATE |
3657 WINED3DPRESENT_INTERVAL_ONE;
3659 pCaps->CursorCaps = WINED3DCURSORCAPS_COLOR |
3660 WINED3DCURSORCAPS_LOWRES;
3662 pCaps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
3663 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
3664 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
3665 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
3666 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
3667 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
3668 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
3669 WINED3DDEVCAPS_PUREDEVICE |
3670 WINED3DDEVCAPS_HWRASTERIZATION |
3671 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
3672 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
3673 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
3674 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
3675 WINED3DDEVCAPS_DRAWPRIMITIVES2EX |
3676 WINED3DDEVCAPS_RTPATCHES;
3678 pCaps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
3679 WINED3DPMISCCAPS_CULLCCW |
3680 WINED3DPMISCCAPS_CULLCW |
3681 WINED3DPMISCCAPS_COLORWRITEENABLE |
3682 WINED3DPMISCCAPS_CLIPTLVERTS |
3683 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
3684 WINED3DPMISCCAPS_MASKZ |
3685 WINED3DPMISCCAPS_BLENDOP |
3686 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING;
3688 WINED3DPMISCCAPS_NULLREFERENCE
3689 WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS
3690 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
3691 WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
3692 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
3694 if(GL_SUPPORT(EXT_BLEND_EQUATION_SEPARATE) && GL_SUPPORT(EXT_BLEND_FUNC_SEPARATE))
3695 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
3697 pCaps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
3698 WINED3DPRASTERCAPS_PAT |
3699 WINED3DPRASTERCAPS_WFOG |
3700 WINED3DPRASTERCAPS_ZFOG |
3701 WINED3DPRASTERCAPS_FOGVERTEX |
3702 WINED3DPRASTERCAPS_FOGTABLE |
3703 WINED3DPRASTERCAPS_STIPPLE |
3704 WINED3DPRASTERCAPS_SUBPIXEL |
3705 WINED3DPRASTERCAPS_ZTEST |
3706 WINED3DPRASTERCAPS_SCISSORTEST |
3707 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
3708 WINED3DPRASTERCAPS_DEPTHBIAS;
3710 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3711 pCaps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY |
3712 WINED3DPRASTERCAPS_ZBIAS |
3713 WINED3DPRASTERCAPS_MIPMAPLODBIAS;
3715 if(GL_SUPPORT(NV_FOG_DISTANCE)) {
3716 pCaps->RasterCaps |= WINED3DPRASTERCAPS_FOGRANGE;
3719 WINED3DPRASTERCAPS_COLORPERSPECTIVE
3720 WINED3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
3721 WINED3DPRASTERCAPS_ANTIALIASEDGES
3722 WINED3DPRASTERCAPS_ZBUFFERLESSHSR
3723 WINED3DPRASTERCAPS_WBUFFER */
3725 pCaps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
3726 WINED3DPCMPCAPS_EQUAL |
3727 WINED3DPCMPCAPS_GREATER |
3728 WINED3DPCMPCAPS_GREATEREQUAL |
3729 WINED3DPCMPCAPS_LESS |
3730 WINED3DPCMPCAPS_LESSEQUAL |
3731 WINED3DPCMPCAPS_NEVER |
3732 WINED3DPCMPCAPS_NOTEQUAL;
3734 pCaps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
3735 WINED3DPBLENDCAPS_BOTHSRCALPHA |
3736 WINED3DPBLENDCAPS_DESTALPHA |
3737 WINED3DPBLENDCAPS_DESTCOLOR |
3738 WINED3DPBLENDCAPS_INVDESTALPHA |
3739 WINED3DPBLENDCAPS_INVDESTCOLOR |
3740 WINED3DPBLENDCAPS_INVSRCALPHA |
3741 WINED3DPBLENDCAPS_INVSRCCOLOR |
3742 WINED3DPBLENDCAPS_ONE |
3743 WINED3DPBLENDCAPS_SRCALPHA |
3744 WINED3DPBLENDCAPS_SRCALPHASAT |
3745 WINED3DPBLENDCAPS_SRCCOLOR |
3746 WINED3DPBLENDCAPS_ZERO;
3748 pCaps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
3749 WINED3DPBLENDCAPS_DESTCOLOR |
3750 WINED3DPBLENDCAPS_INVDESTALPHA |
3751 WINED3DPBLENDCAPS_INVDESTCOLOR |
3752 WINED3DPBLENDCAPS_INVSRCALPHA |
3753 WINED3DPBLENDCAPS_INVSRCCOLOR |
3754 WINED3DPBLENDCAPS_ONE |
3755 WINED3DPBLENDCAPS_SRCALPHA |
3756 WINED3DPBLENDCAPS_SRCCOLOR |
3757 WINED3DPBLENDCAPS_ZERO;
3758 /* NOTE: WINED3DPBLENDCAPS_SRCALPHASAT is not supported as dest blend factor,
3759 * according to the glBlendFunc manpage
3761 * WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA are
3762 * legacy settings for srcblend only
3765 if( GL_SUPPORT(EXT_BLEND_COLOR)) {
3766 pCaps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
3767 pCaps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
3771 pCaps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
3772 WINED3DPCMPCAPS_EQUAL |
3773 WINED3DPCMPCAPS_GREATER |
3774 WINED3DPCMPCAPS_GREATEREQUAL |
3775 WINED3DPCMPCAPS_LESS |
3776 WINED3DPCMPCAPS_LESSEQUAL |
3777 WINED3DPCMPCAPS_NEVER |
3778 WINED3DPCMPCAPS_NOTEQUAL;
3780 pCaps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
3781 WINED3DPSHADECAPS_COLORGOURAUDRGB |
3782 WINED3DPSHADECAPS_ALPHAFLATBLEND |
3783 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
3784 WINED3DPSHADECAPS_COLORFLATRGB |
3785 WINED3DPSHADECAPS_FOGFLAT |
3786 WINED3DPSHADECAPS_FOGGOURAUD |
3787 WINED3DPSHADECAPS_SPECULARFLATRGB;
3789 pCaps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
3790 WINED3DPTEXTURECAPS_ALPHAPALETTE |
3791 WINED3DPTEXTURECAPS_TRANSPARENCY |
3792 WINED3DPTEXTURECAPS_BORDER |
3793 WINED3DPTEXTURECAPS_MIPMAP |
3794 WINED3DPTEXTURECAPS_PROJECTED |
3795 WINED3DPTEXTURECAPS_PERSPECTIVE;
3797 if( !GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
3798 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
3799 WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
3802 if( GL_SUPPORT(EXT_TEXTURE3D)) {
3803 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP |
3804 WINED3DPTEXTURECAPS_MIPVOLUMEMAP |
3805 WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
3808 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
3809 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP |
3810 WINED3DPTEXTURECAPS_MIPCUBEMAP |
3811 WINED3DPTEXTURECAPS_CUBEMAP_POW2;
3815 pCaps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3816 WINED3DPTFILTERCAPS_MAGFPOINT |
3817 WINED3DPTFILTERCAPS_MINFLINEAR |
3818 WINED3DPTFILTERCAPS_MINFPOINT |
3819 WINED3DPTFILTERCAPS_MIPFLINEAR |
3820 WINED3DPTFILTERCAPS_MIPFPOINT |
3821 WINED3DPTFILTERCAPS_LINEAR |
3822 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3823 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3824 WINED3DPTFILTERCAPS_MIPLINEAR |
3825 WINED3DPTFILTERCAPS_MIPNEAREST |
3826 WINED3DPTFILTERCAPS_NEAREST;
3828 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3829 pCaps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
3830 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
3833 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
3834 pCaps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3835 WINED3DPTFILTERCAPS_MAGFPOINT |
3836 WINED3DPTFILTERCAPS_MINFLINEAR |
3837 WINED3DPTFILTERCAPS_MINFPOINT |
3838 WINED3DPTFILTERCAPS_MIPFLINEAR |
3839 WINED3DPTFILTERCAPS_MIPFPOINT |
3840 WINED3DPTFILTERCAPS_LINEAR |
3841 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3842 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3843 WINED3DPTFILTERCAPS_MIPLINEAR |
3844 WINED3DPTFILTERCAPS_MIPNEAREST |
3845 WINED3DPTFILTERCAPS_NEAREST;
3847 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3848 pCaps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
3849 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
3852 pCaps->CubeTextureFilterCaps = 0;
3854 if (GL_SUPPORT(EXT_TEXTURE3D)) {
3855 pCaps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3856 WINED3DPTFILTERCAPS_MAGFPOINT |
3857 WINED3DPTFILTERCAPS_MINFLINEAR |
3858 WINED3DPTFILTERCAPS_MINFPOINT |
3859 WINED3DPTFILTERCAPS_MIPFLINEAR |
3860 WINED3DPTFILTERCAPS_MIPFPOINT |
3861 WINED3DPTFILTERCAPS_LINEAR |
3862 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3863 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3864 WINED3DPTFILTERCAPS_MIPLINEAR |
3865 WINED3DPTFILTERCAPS_MIPNEAREST |
3866 WINED3DPTFILTERCAPS_NEAREST;
3868 pCaps->VolumeTextureFilterCaps = 0;
3870 pCaps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
3871 WINED3DPTADDRESSCAPS_CLAMP |
3872 WINED3DPTADDRESSCAPS_WRAP;
3874 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
3875 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
3877 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
3878 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
3880 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
3881 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
3884 if (GL_SUPPORT(EXT_TEXTURE3D)) {
3885 pCaps->VolumeTextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
3886 WINED3DPTADDRESSCAPS_CLAMP |
3887 WINED3DPTADDRESSCAPS_WRAP;
3888 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
3889 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
3891 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
3892 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
3894 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
3895 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
3898 pCaps->VolumeTextureAddressCaps = 0;
3900 pCaps->LineCaps = WINED3DLINECAPS_TEXTURE |
3901 WINED3DLINECAPS_ZTEST |
3902 WINED3DLINECAPS_BLEND |
3903 WINED3DLINECAPS_ALPHACMP |
3904 WINED3DLINECAPS_FOG;
3905 /* WINED3DLINECAPS_ANTIALIAS is not supported on Windows, and dx and gl seem to have a different
3906 * idea how generating the smoothing alpha values works; the result is different
3909 pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
3910 pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
3912 if(GL_SUPPORT(EXT_TEXTURE3D))
3913 pCaps->MaxVolumeExtent = GL_LIMITS(texture3d_size);
3915 pCaps->MaxVolumeExtent = 0;
3917 pCaps->MaxTextureRepeat = 32768;
3918 pCaps->MaxTextureAspectRatio = GL_LIMITS(texture_size);
3919 pCaps->MaxVertexW = 1.0f;
3921 pCaps->GuardBandLeft = 0.0f;
3922 pCaps->GuardBandTop = 0.0f;
3923 pCaps->GuardBandRight = 0.0f;
3924 pCaps->GuardBandBottom = 0.0f;
3926 pCaps->ExtentsAdjust = 0.0f;
3928 pCaps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
3929 WINED3DSTENCILCAPS_INCRSAT |
3930 WINED3DSTENCILCAPS_INVERT |
3931 WINED3DSTENCILCAPS_KEEP |
3932 WINED3DSTENCILCAPS_REPLACE |
3933 WINED3DSTENCILCAPS_ZERO;
3934 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
3935 pCaps->StencilCaps |= WINED3DSTENCILCAPS_DECR |
3936 WINED3DSTENCILCAPS_INCR;
3938 if (GL_SUPPORT(EXT_STENCIL_TWO_SIDE) || GL_SUPPORT(ATI_SEPARATE_STENCIL)) {
3939 pCaps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
3942 pCaps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
3944 pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
3945 pCaps->MaxActiveLights = GL_LIMITS(lights);
3947 pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
3948 pCaps->MaxVertexBlendMatrixIndex = 0;
3950 pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
3951 pCaps->MaxPointSize = GL_LIMITS(pointsize);
3954 pCaps->VertexProcessingCaps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
3955 WINED3DVTXPCAPS_MATERIALSOURCE7 |
3956 WINED3DVTXPCAPS_POSITIONALLIGHTS |
3957 WINED3DVTXPCAPS_LOCALVIEWER |
3958 WINED3DVTXPCAPS_VERTEXFOG |
3959 WINED3DVTXPCAPS_TEXGEN;
3961 D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
3963 pCaps->MaxPrimitiveCount = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
3964 pCaps->MaxVertexIndex = 0xFFFFF;
3965 pCaps->MaxStreams = MAX_STREAMS;
3966 pCaps->MaxStreamStride = 1024;
3968 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
3969 pCaps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET |
3970 WINED3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
3971 pCaps->MaxNpatchTessellationLevel = 0;
3972 pCaps->MasterAdapterOrdinal = 0;
3973 pCaps->AdapterOrdinalInGroup = 0;
3974 pCaps->NumberOfAdaptersInGroup = 1;
3976 pCaps->NumSimultaneousRTs = GL_LIMITS(buffers);
3978 pCaps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
3979 WINED3DPTFILTERCAPS_MAGFPOINT |
3980 WINED3DPTFILTERCAPS_MINFLINEAR |
3981 WINED3DPTFILTERCAPS_MAGFLINEAR;
3982 pCaps->VertexTextureFilterCaps = 0;
3984 memset(&shader_caps, 0, sizeof(shader_caps));
3985 shader_backend = select_shader_backend(adapter, DeviceType);
3986 shader_backend->shader_get_caps(DeviceType, &adapter->gl_info, &shader_caps);
3988 memset(&fragment_caps, 0, sizeof(fragment_caps));
3989 frag_pipeline = select_fragment_implementation(adapter, DeviceType);
3990 frag_pipeline->get_caps(DeviceType, &adapter->gl_info, &fragment_caps);
3992 /* Add shader misc caps. Only some of them belong to the shader parts of the pipeline */
3993 pCaps->PrimitiveMiscCaps |= fragment_caps.PrimitiveMiscCaps;
3995 /* This takes care for disabling vertex shader or pixel shader caps while leaving the other one enabled.
3996 * Ignore shader model capabilities if disabled in config
3998 if(vs_selected_mode == SHADER_NONE) {
3999 TRACE_(d3d_caps)("Vertex shader disabled in config, reporting version 0.0\n");
4000 pCaps->VertexShaderVersion = WINED3DVS_VERSION(0,0);
4001 pCaps->MaxVertexShaderConst = 0;
4003 pCaps->VertexShaderVersion = shader_caps.VertexShaderVersion;
4004 pCaps->MaxVertexShaderConst = shader_caps.MaxVertexShaderConst;
4007 if(ps_selected_mode == SHADER_NONE) {
4008 TRACE_(d3d_caps)("Pixel shader disabled in config, reporting version 0.0\n");
4009 pCaps->PixelShaderVersion = WINED3DPS_VERSION(0,0);
4010 pCaps->PixelShader1xMaxValue = 0.0f;
4012 pCaps->PixelShaderVersion = shader_caps.PixelShaderVersion;
4013 pCaps->PixelShader1xMaxValue = shader_caps.PixelShader1xMaxValue;
4016 pCaps->TextureOpCaps = fragment_caps.TextureOpCaps;
4017 pCaps->MaxTextureBlendStages = fragment_caps.MaxTextureBlendStages;
4018 pCaps->MaxSimultaneousTextures = fragment_caps.MaxSimultaneousTextures;
4020 pCaps->VS20Caps = shader_caps.VS20Caps;
4021 pCaps->MaxVShaderInstructionsExecuted = shader_caps.MaxVShaderInstructionsExecuted;
4022 pCaps->MaxVertexShader30InstructionSlots= shader_caps.MaxVertexShader30InstructionSlots;
4023 pCaps->PS20Caps = shader_caps.PS20Caps;
4024 pCaps->MaxPShaderInstructionsExecuted = shader_caps.MaxPShaderInstructionsExecuted;
4025 pCaps->MaxPixelShader30InstructionSlots = shader_caps.MaxPixelShader30InstructionSlots;
4027 /* The following caps are shader specific, but they are things we cannot detect, or which
4028 * are the same among all shader models. So to avoid code duplication set the shader version
4029 * specific, but otherwise constant caps here
4031 if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(3,0)) {
4032 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
4033 use the VS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum VS3.0 value. */
4034 pCaps->VS20Caps.Caps = WINED3DVS20CAPS_PREDICATION;
4035 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
4036 pCaps->VS20Caps.NumTemps = max(32, adapter->gl_info.vs_arb_max_temps);
4037 pCaps->VS20Caps.StaticFlowControlDepth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH ; /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
4039 pCaps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
4040 pCaps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.vs_arb_max_instructions);
4041 } else if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(2,0)) {
4042 pCaps->VS20Caps.Caps = 0;
4043 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
4044 pCaps->VS20Caps.NumTemps = max(12, adapter->gl_info.vs_arb_max_temps);
4045 pCaps->VS20Caps.StaticFlowControlDepth = 1;
4047 pCaps->MaxVShaderInstructionsExecuted = 65535;
4048 pCaps->MaxVertexShader30InstructionSlots = 0;
4049 } else { /* VS 1.x */
4050 pCaps->VS20Caps.Caps = 0;
4051 pCaps->VS20Caps.DynamicFlowControlDepth = 0;
4052 pCaps->VS20Caps.NumTemps = 0;
4053 pCaps->VS20Caps.StaticFlowControlDepth = 0;
4055 pCaps->MaxVShaderInstructionsExecuted = 0;
4056 pCaps->MaxVertexShader30InstructionSlots = 0;
4059 if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(3,0)) {
4060 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
4061 use the PS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum PS 3.0 value. */
4063 /* 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 */
4064 pCaps->PS20Caps.Caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
4065 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
4066 WINED3DPS20CAPS_PREDICATION |
4067 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
4068 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
4069 pCaps->PS20Caps.DynamicFlowControlDepth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
4070 pCaps->PS20Caps.NumTemps = max(32, adapter->gl_info.ps_arb_max_temps);
4071 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
4072 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
4074 pCaps->MaxPShaderInstructionsExecuted = 65535;
4075 pCaps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS, adapter->gl_info.ps_arb_max_instructions);
4076 } else if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(2,0)) {
4077 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
4078 pCaps->PS20Caps.Caps = 0;
4079 pCaps->PS20Caps.DynamicFlowControlDepth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
4080 pCaps->PS20Caps.NumTemps = max(12, adapter->gl_info.ps_arb_max_temps);
4081 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
4082 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
4084 pCaps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
4085 pCaps->MaxPixelShader30InstructionSlots = 0;
4086 } else { /* PS 1.x */
4087 pCaps->PS20Caps.Caps = 0;
4088 pCaps->PS20Caps.DynamicFlowControlDepth = 0;
4089 pCaps->PS20Caps.NumTemps = 0;
4090 pCaps->PS20Caps.StaticFlowControlDepth = 0;
4091 pCaps->PS20Caps.NumInstructionSlots = 0;
4093 pCaps->MaxPShaderInstructionsExecuted = 0;
4094 pCaps->MaxPixelShader30InstructionSlots = 0;
4097 if(pCaps->VertexShaderVersion >= WINED3DVS_VERSION(2,0)) {
4098 /* OpenGL supports all the formats below, perhaps not always
4099 * without conversion, but it supports them.
4100 * Further GLSL doesn't seem to have an official unsigned type so
4101 * don't advertise it yet as I'm not sure how we handle it.
4102 * We might need to add some clamping in the shader engine to
4104 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
4105 pCaps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
4106 WINED3DDTCAPS_UBYTE4N |
4107 WINED3DDTCAPS_SHORT2N |
4108 WINED3DDTCAPS_SHORT4N;
4109 if (GL_SUPPORT(ARB_HALF_FLOAT_VERTEX)) {
4110 pCaps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
4111 WINED3DDTCAPS_FLOAT16_4;
4114 pCaps->DeclTypes = 0;
4116 /* Set DirectDraw helper Caps */
4117 ckey_caps = WINEDDCKEYCAPS_DESTBLT |
4118 WINEDDCKEYCAPS_SRCBLT;
4119 fx_caps = WINEDDFXCAPS_BLTALPHA |
4120 WINEDDFXCAPS_BLTMIRRORLEFTRIGHT |
4121 WINEDDFXCAPS_BLTMIRRORUPDOWN |
4122 WINEDDFXCAPS_BLTROTATION90 |
4123 WINEDDFXCAPS_BLTSHRINKX |
4124 WINEDDFXCAPS_BLTSHRINKXN |
4125 WINEDDFXCAPS_BLTSHRINKY |
4126 WINEDDFXCAPS_BLTSHRINKXN |
4127 WINEDDFXCAPS_BLTSTRETCHX |
4128 WINEDDFXCAPS_BLTSTRETCHXN |
4129 WINEDDFXCAPS_BLTSTRETCHY |
4130 WINEDDFXCAPS_BLTSTRETCHYN;
4131 blit_caps = WINEDDCAPS_BLT |
4132 WINEDDCAPS_BLTCOLORFILL |
4133 WINEDDCAPS_BLTDEPTHFILL |
4134 WINEDDCAPS_BLTSTRETCH |
4135 WINEDDCAPS_CANBLTSYSMEM |
4136 WINEDDCAPS_CANCLIP |
4137 WINEDDCAPS_CANCLIPSTRETCHED |
4138 WINEDDCAPS_COLORKEY |
4139 WINEDDCAPS_COLORKEYHWASSIST |
4140 WINEDDCAPS_ALIGNBOUNDARYSRC;
4142 /* Fill the ddraw caps structure */
4143 pCaps->DirectDrawCaps.Caps = WINEDDCAPS_GDI |
4144 WINEDDCAPS_PALETTE |
4146 pCaps->DirectDrawCaps.Caps2 = WINEDDCAPS2_CERTIFIED |
4147 WINEDDCAPS2_NOPAGELOCKREQUIRED |
4148 WINEDDCAPS2_PRIMARYGAMMA |
4149 WINEDDCAPS2_WIDESURFACES |
4150 WINEDDCAPS2_CANRENDERWINDOWED;
4151 pCaps->DirectDrawCaps.SVBCaps = blit_caps;
4152 pCaps->DirectDrawCaps.SVBCKeyCaps = ckey_caps;
4153 pCaps->DirectDrawCaps.SVBFXCaps = fx_caps;
4154 pCaps->DirectDrawCaps.VSBCaps = blit_caps;
4155 pCaps->DirectDrawCaps.VSBCKeyCaps = ckey_caps;
4156 pCaps->DirectDrawCaps.VSBFXCaps = fx_caps;
4157 pCaps->DirectDrawCaps.SSBCaps = blit_caps;
4158 pCaps->DirectDrawCaps.SSBCKeyCaps = ckey_caps;
4159 pCaps->DirectDrawCaps.SSBFXCaps = fx_caps;
4161 pCaps->DirectDrawCaps.ddsCaps = WINEDDSCAPS_ALPHA |
4162 WINEDDSCAPS_BACKBUFFER |
4164 WINEDDSCAPS_FRONTBUFFER |
4165 WINEDDSCAPS_OFFSCREENPLAIN |
4166 WINEDDSCAPS_PALETTE |
4167 WINEDDSCAPS_PRIMARYSURFACE |
4168 WINEDDSCAPS_SYSTEMMEMORY |
4169 WINEDDSCAPS_VIDEOMEMORY |
4170 WINEDDSCAPS_VISIBLE;
4171 pCaps->DirectDrawCaps.StrideAlign = DDRAW_PITCH_ALIGNMENT;
4173 /* Set D3D caps if OpenGL is available. */
4174 if (adapter->opengl)
4176 pCaps->DirectDrawCaps.ddsCaps |=WINEDDSCAPS_3DDEVICE |
4177 WINEDDSCAPS_MIPMAP |
4178 WINEDDSCAPS_TEXTURE |
4179 WINEDDSCAPS_ZBUFFER;
4180 pCaps->DirectDrawCaps.Caps |= WINEDDCAPS_3D;
4186 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
4187 and fields being inserted in the middle, a new structure is used in place */
4188 static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter,
4189 WINED3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviourFlags, IUnknown *parent,
4190 IWineD3DDeviceParent *device_parent, IWineD3DDevice **ppReturnedDeviceInterface)
4192 IWineD3DDeviceImpl *object = NULL;
4193 IWineD3DImpl *This = (IWineD3DImpl *)iface;
4194 struct WineD3DAdapter *adapter = &This->adapters[Adapter];
4195 WINED3DDISPLAYMODE mode;
4196 const struct fragment_pipeline *frag_pipeline = NULL;
4198 struct fragment_caps ffp_caps;
4199 struct shader_caps shader_caps;
4202 /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
4203 * number and create a device without a 3D adapter for 2D only operation.
4205 if (IWineD3D_GetAdapterCount(iface) && Adapter >= IWineD3D_GetAdapterCount(iface)) {
4206 return WINED3DERR_INVALIDCALL;
4209 /* Create a WineD3DDevice object */
4210 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
4211 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
4212 TRACE("Created WineD3DDevice object @ %p\n", object);
4213 if (NULL == object) {
4214 return WINED3DERR_OUTOFVIDEOMEMORY;
4217 /* Set up initial COM information */
4218 object->lpVtbl = &IWineD3DDevice_Vtbl;
4220 object->wineD3D = iface;
4221 object->adapter = This->adapter_count ? adapter : NULL;
4222 IWineD3D_AddRef(object->wineD3D);
4223 object->parent = parent;
4224 object->device_parent = device_parent;
4225 list_init(&object->resources);
4226 list_init(&object->shaders);
4228 if(This->dxVersion == 7) {
4229 object->surface_alignment = DDRAW_PITCH_ALIGNMENT;
4231 object->surface_alignment = D3D8_PITCH_ALIGNMENT;
4233 object->posFixup[0] = 1.0f; /* This is needed to get the x coord unmodified through a MAD. */
4235 /* Set the state up as invalid until the device is fully created */
4236 object->state = WINED3DERR_DRIVERINTERNALERROR;
4238 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %x, RetDevInt: %p)\n", This, Adapter, DeviceType,
4239 hFocusWindow, BehaviourFlags, ppReturnedDeviceInterface);
4241 /* Save the creation parameters */
4242 object->createParms.AdapterOrdinal = Adapter;
4243 object->createParms.DeviceType = DeviceType;
4244 object->createParms.hFocusWindow = hFocusWindow;
4245 object->createParms.BehaviorFlags = BehaviourFlags;
4247 /* Initialize other useful values */
4248 object->adapterNo = Adapter;
4249 object->devType = DeviceType;
4251 select_shader_mode(&adapter->gl_info, DeviceType,
4252 &object->ps_selected_mode, &object->vs_selected_mode);
4253 object->shader_backend = select_shader_backend(adapter, DeviceType);
4255 memset(&shader_caps, 0, sizeof(shader_caps));
4256 object->shader_backend->shader_get_caps(DeviceType, &adapter->gl_info, &shader_caps);
4257 object->d3d_vshader_constantF = shader_caps.MaxVertexShaderConst;
4258 object->d3d_pshader_constantF = shader_caps.MaxPixelShaderConst;
4259 object->vs_clipping = shader_caps.VSClipping;
4261 memset(&ffp_caps, 0, sizeof(ffp_caps));
4262 frag_pipeline = select_fragment_implementation(adapter, DeviceType);
4263 object->frag_pipe = frag_pipeline;
4264 frag_pipeline->get_caps(DeviceType, &adapter->gl_info, &ffp_caps);
4265 object->max_ffp_textures = ffp_caps.MaxSimultaneousTextures;
4266 object->max_ffp_texture_stages = ffp_caps.MaxTextureBlendStages;
4267 hr = compile_state_table(object->StateTable, object->multistate_funcs, &adapter->gl_info,
4268 ffp_vertexstate_template, frag_pipeline, misc_state_template);
4271 IWineD3D_Release(object->wineD3D);
4272 HeapFree(GetProcessHeap(), 0, object);
4277 object->blitter = select_blit_implementation(adapter, DeviceType);
4279 /* set the state of the device to valid */
4280 object->state = WINED3D_OK;
4282 /* Get the initial screen setup for ddraw */
4283 IWineD3DImpl_GetAdapterDisplayMode(iface, Adapter, &mode);
4285 object->ddraw_width = mode.Width;
4286 object->ddraw_height = mode.Height;
4287 object->ddraw_format = mode.Format;
4289 for(i = 0; i < PATCHMAP_SIZE; i++) {
4290 list_init(&object->patches[i]);
4293 IWineD3DDeviceParent_WineD3DDeviceCreated(device_parent, *ppReturnedDeviceInterface);
4298 static HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
4299 IWineD3DImpl *This = (IWineD3DImpl *)iface;
4300 IUnknown_AddRef(This->parent);
4301 *pParent = This->parent;
4305 ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface) {
4306 IUnknown* surfaceParent;
4307 TRACE("(%p) call back\n", pSurface);
4309 /* Now, release the parent, which will take care of cleaning up the surface for us */
4310 IWineD3DSurface_GetParent(pSurface, &surfaceParent);
4311 IUnknown_Release(surfaceParent);
4312 return IUnknown_Release(surfaceParent);
4315 ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pVolume) {
4316 IUnknown* volumeParent;
4317 TRACE("(%p) call back\n", pVolume);
4319 /* Now, release the parent, which will take care of cleaning up the volume for us */
4320 IWineD3DVolume_GetParent(pVolume, &volumeParent);
4321 IUnknown_Release(volumeParent);
4322 return IUnknown_Release(volumeParent);
4325 static void WINE_GLAPI invalid_func(const void *data)
4327 ERR("Invalid vertex attribute function called\n");
4331 static void WINE_GLAPI invalid_texcoord_func(GLenum unit, const void *data)
4333 ERR("Invalid texcoord function called\n");
4337 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
4338 * the extension detection and are used in drawStridedSlow
4340 static void WINE_GLAPI position_d3dcolor(const void *data)
4342 DWORD pos = *((const DWORD *)data);
4344 FIXME("Add a test for fixed function position from d3dcolor type\n");
4345 glVertex4s(D3DCOLOR_B_R(pos),
4351 static void WINE_GLAPI position_float4(const void *data)
4353 const GLfloat *pos = data;
4355 if (pos[3] != 0.0f && pos[3] != 1.0f)
4357 float w = 1.0f / pos[3];
4359 glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
4367 static void WINE_GLAPI diffuse_d3dcolor(const void *data)
4369 DWORD diffuseColor = *((const DWORD *)data);
4371 glColor4ub(D3DCOLOR_B_R(diffuseColor),
4372 D3DCOLOR_B_G(diffuseColor),
4373 D3DCOLOR_B_B(diffuseColor),
4374 D3DCOLOR_B_A(diffuseColor));
4377 static void WINE_GLAPI specular_d3dcolor(const void *data)
4379 DWORD specularColor = *((const DWORD *)data);
4380 GLbyte d[] = {D3DCOLOR_B_R(specularColor),
4381 D3DCOLOR_B_G(specularColor),
4382 D3DCOLOR_B_B(specularColor)};
4384 specular_func_3ubv(d);
4387 static void WINE_GLAPI warn_no_specular_func(const void *data)
4389 WARN("GL_EXT_secondary_color not supported\n");
4392 static void fillGLAttribFuncs(const struct wined3d_gl_info *gl_info)
4394 position_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4395 position_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4396 position_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)glVertex3fv;
4397 position_funcs[WINED3D_FFP_EMIT_FLOAT4] = position_float4;
4398 position_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = position_d3dcolor;
4399 position_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4400 position_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4401 position_funcs[WINED3D_FFP_EMIT_SHORT4] = (glAttribFunc)glVertex2sv;
4402 position_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4403 position_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4404 position_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4405 position_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4406 position_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4407 position_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4408 position_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4409 position_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4410 position_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4412 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4413 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4414 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)glColor3fv;
4415 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glAttribFunc)glColor4fv;
4416 diffuse_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = diffuse_d3dcolor;
4417 diffuse_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4418 diffuse_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4419 diffuse_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4420 diffuse_funcs[WINED3D_FFP_EMIT_UBYTE4N] = (glAttribFunc)glColor4ubv;
4421 diffuse_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4422 diffuse_funcs[WINED3D_FFP_EMIT_SHORT4N] = (glAttribFunc)glColor4sv;
4423 diffuse_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4424 diffuse_funcs[WINED3D_FFP_EMIT_USHORT4N] = (glAttribFunc)glColor4usv;
4425 diffuse_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4426 diffuse_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4427 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4428 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4430 /* No 4 component entry points here */
4431 specular_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4432 specular_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4433 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
4434 specular_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)GL_EXTCALL(glSecondaryColor3fvEXT);
4436 specular_funcs[WINED3D_FFP_EMIT_FLOAT3] = warn_no_specular_func;
4438 specular_funcs[WINED3D_FFP_EMIT_FLOAT4] = invalid_func;
4439 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
4440 specular_func_3ubv = (glAttribFunc)GL_EXTCALL(glSecondaryColor3ubvEXT);
4441 specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = specular_d3dcolor;
4443 specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = warn_no_specular_func;
4445 specular_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4446 specular_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4447 specular_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4448 specular_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4449 specular_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4450 specular_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4451 specular_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4452 specular_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4453 specular_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4454 specular_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4455 specular_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4456 specular_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4458 /* Only 3 component entry points here. Test how others behave. Float4 normals are used
4459 * by one of our tests, trying to pass it to the pixel shader, which fails on Windows.
4461 normal_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4462 normal_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4463 normal_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)glNormal3fv;
4464 normal_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glAttribFunc)glNormal3fv; /* Just ignore the 4th value */
4465 normal_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_func;
4466 normal_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4467 normal_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4468 normal_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4469 normal_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4470 normal_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4471 normal_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4472 normal_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4473 normal_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4474 normal_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4475 normal_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4476 normal_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4477 normal_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4479 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT1] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord1fvARB);
4480 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2fvARB);
4481 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord3fvARB);
4482 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4fvARB);
4483 multi_texcoord_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_texcoord_func;
4484 multi_texcoord_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_texcoord_func;
4485 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2svARB);
4486 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4svARB);
4487 multi_texcoord_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_texcoord_func;
4488 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_texcoord_func;
4489 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_texcoord_func;
4490 multi_texcoord_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_texcoord_func;
4491 multi_texcoord_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_texcoord_func;
4492 multi_texcoord_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_texcoord_func;
4493 multi_texcoord_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_texcoord_func;
4494 if (GL_SUPPORT(NV_HALF_FLOAT))
4496 /* Not supported by ARB_HALF_FLOAT_VERTEX, so check for NV_HALF_FLOAT */
4497 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2hvNV);
4498 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4hvNV);
4500 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_texcoord_func;
4501 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_texcoord_func;
4505 BOOL InitAdapters(IWineD3DImpl *This)
4507 static HMODULE mod_gl;
4509 int ps_selected_mode, vs_selected_mode;
4511 /* No need to hold any lock. The calling library makes sure only one thread calls
4512 * wined3d simultaneously
4515 TRACE("Initializing adapters\n");
4518 #ifdef USE_WIN32_OPENGL
4519 #define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
4520 mod_gl = LoadLibraryA("opengl32.dll");
4522 ERR("Can't load opengl32.dll!\n");
4526 #define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
4527 /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
4528 mod_gl = GetModuleHandleA("gdi32.dll");
4532 /* Load WGL core functions from opengl32.dll */
4533 #define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn);
4537 if(!pwglGetProcAddress) {
4538 ERR("Unable to load wglGetProcAddress!\n");
4542 /* Dynamically load all GL core functions */
4546 /* Load glFinish and glFlush from opengl32.dll even if we're not using WIN32 opengl
4547 * otherwise because we have to use winex11.drv's override
4549 #ifdef USE_WIN32_OPENGL
4550 wglFinish = (void*)GetProcAddress(mod_gl, "glFinish");
4551 wglFlush = (void*)GetProcAddress(mod_gl, "glFlush");
4553 wglFinish = (void*)pwglGetProcAddress("wglFinish");
4554 wglFlush = (void*)pwglGetProcAddress("wglFlush");
4557 glEnableWINE = glEnable;
4558 glDisableWINE = glDisable;
4560 /* For now only one default adapter */
4562 struct WineD3DAdapter *adapter = &This->adapters[0];
4563 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
4564 struct wined3d_fake_gl_ctx fake_gl_ctx = {0};
4568 WineD3D_PixelFormat *cfgs;
4569 DISPLAY_DEVICEW DisplayDevice;
4572 TRACE("Initializing default adapter\n");
4574 adapter->monitorPoint.x = -1;
4575 adapter->monitorPoint.y = -1;
4577 if (!WineD3D_CreateFakeGLContext(&fake_gl_ctx))
4579 ERR("Failed to get a gl context for default adapter\n");
4583 ret = IWineD3DImpl_FillGLCaps(&adapter->gl_info);
4585 ERR("Failed to initialize gl caps for default adapter\n");
4586 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
4589 ret = initPixelFormats(&adapter->gl_info);
4591 ERR("Failed to init gl formats\n");
4592 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
4596 hdc = fake_gl_ctx.dc;
4598 adapter->driver = "Display";
4599 adapter->description = "Direct3D HAL";
4601 /* Use the VideoRamSize registry setting when set */
4602 if(wined3d_settings.emulated_textureram)
4603 adapter->TextureRam = wined3d_settings.emulated_textureram;
4605 adapter->TextureRam = adapter->gl_info.vidmem;
4606 adapter->UsedTextureRam = 0;
4607 TRACE("Emulating %dMB of texture ram\n", adapter->TextureRam/(1024*1024));
4609 /* Initialize the Adapter's DeviceName which is required for ChangeDisplaySettings and friends */
4610 DisplayDevice.cb = sizeof(DisplayDevice);
4611 EnumDisplayDevicesW(NULL, 0 /* Adapter 0 = iDevNum 0 */, &DisplayDevice, 0);
4612 TRACE("DeviceName: %s\n", debugstr_w(DisplayDevice.DeviceName));
4613 strcpyW(adapter->DeviceName, DisplayDevice.DeviceName);
4615 if(GL_SUPPORT(WGL_ARB_PIXEL_FORMAT))
4622 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
4623 GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, &attribute, &adapter->nCfgs));
4625 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, adapter->nCfgs *sizeof(WineD3D_PixelFormat));
4626 cfgs = adapter->cfgs;
4627 attribs[nAttribs++] = WGL_RED_BITS_ARB;
4628 attribs[nAttribs++] = WGL_GREEN_BITS_ARB;
4629 attribs[nAttribs++] = WGL_BLUE_BITS_ARB;
4630 attribs[nAttribs++] = WGL_ALPHA_BITS_ARB;
4631 attribs[nAttribs++] = WGL_DEPTH_BITS_ARB;
4632 attribs[nAttribs++] = WGL_STENCIL_BITS_ARB;
4633 attribs[nAttribs++] = WGL_DRAW_TO_WINDOW_ARB;
4634 attribs[nAttribs++] = WGL_PIXEL_TYPE_ARB;
4635 attribs[nAttribs++] = WGL_DOUBLE_BUFFER_ARB;
4636 attribs[nAttribs++] = WGL_AUX_BUFFERS_ARB;
4638 for (iPixelFormat=1; iPixelFormat <= adapter->nCfgs; ++iPixelFormat)
4640 res = GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, nAttribs, attribs, values));
4645 /* Cache the pixel format */
4646 cfgs->iPixelFormat = iPixelFormat;
4647 cfgs->redSize = values[0];
4648 cfgs->greenSize = values[1];
4649 cfgs->blueSize = values[2];
4650 cfgs->alphaSize = values[3];
4651 cfgs->depthSize = values[4];
4652 cfgs->stencilSize = values[5];
4653 cfgs->windowDrawable = values[6];
4654 cfgs->iPixelType = values[7];
4655 cfgs->doubleBuffer = values[8];
4656 cfgs->auxBuffers = values[9];
4658 cfgs->pbufferDrawable = FALSE;
4659 /* Check for pbuffer support when it is around as wglGetPixelFormatAttribiv fails for unknown attributes. */
4660 if(GL_SUPPORT(WGL_ARB_PBUFFER)) {
4661 int attrib = WGL_DRAW_TO_PBUFFER_ARB;
4663 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 1, &attrib, &value)))
4664 cfgs->pbufferDrawable = value;
4667 cfgs->numSamples = 0;
4668 /* Check multisample support */
4669 if(GL_SUPPORT(ARB_MULTISAMPLE)) {
4670 int attrib[2] = {WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB};
4672 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 2, attrib, value))) {
4673 /* value[0] = WGL_SAMPLE_BUFFERS_ARB which tells whether multisampling is supported.
4674 * value[1] = number of multi sample buffers*/
4676 cfgs->numSamples = value[1];
4680 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, depth=%d, stencil=%d, windowDrawable=%d, pbufferDrawable=%d\n", cfgs->iPixelFormat, cfgs->iPixelType, cfgs->doubleBuffer, cfgs->redSize, cfgs->greenSize, cfgs->blueSize, cfgs->alphaSize, cfgs->depthSize, cfgs->stencilSize, cfgs->windowDrawable, cfgs->pbufferDrawable);
4686 int nCfgs = DescribePixelFormat(hdc, 0, 0, 0);
4687 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nCfgs*sizeof(WineD3D_PixelFormat));
4688 adapter->nCfgs = 0; /* We won't accept all formats e.g. software accelerated ones will be skipped */
4690 cfgs = adapter->cfgs;
4691 for(iPixelFormat=1; iPixelFormat<=nCfgs; iPixelFormat++)
4693 PIXELFORMATDESCRIPTOR ppfd;
4695 res = DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &ppfd);
4699 /* We only want HW acceleration using an OpenGL ICD driver.
4700 * PFD_GENERIC_FORMAT = slow opengl 1.1 gdi software rendering
4701 * PFD_GENERIC_ACCELERATED = partial hw acceleration using a MCD driver (e.g. 3dfx minigl)
4703 if(ppfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED))
4705 TRACE("Skipping iPixelFormat=%d because it isn't ICD accelerated\n", iPixelFormat);
4709 cfgs->iPixelFormat = iPixelFormat;
4710 cfgs->redSize = ppfd.cRedBits;
4711 cfgs->greenSize = ppfd.cGreenBits;
4712 cfgs->blueSize = ppfd.cBlueBits;
4713 cfgs->alphaSize = ppfd.cAlphaBits;
4714 cfgs->depthSize = ppfd.cDepthBits;
4715 cfgs->stencilSize = ppfd.cStencilBits;
4716 cfgs->pbufferDrawable = 0;
4717 cfgs->windowDrawable = (ppfd.dwFlags & PFD_DRAW_TO_WINDOW) ? 1 : 0;
4718 cfgs->iPixelType = (ppfd.iPixelType == PFD_TYPE_RGBA) ? WGL_TYPE_RGBA_ARB : WGL_TYPE_COLORINDEX_ARB;
4719 cfgs->doubleBuffer = (ppfd.dwFlags & PFD_DOUBLEBUFFER) ? 1 : 0;
4720 cfgs->auxBuffers = ppfd.cAuxBuffers;
4721 cfgs->numSamples = 0;
4723 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, depth=%d, stencil=%d, windowDrawable=%d, pbufferDrawable=%d\n", cfgs->iPixelFormat, cfgs->iPixelType, cfgs->doubleBuffer, cfgs->redSize, cfgs->greenSize, cfgs->blueSize, cfgs->alphaSize, cfgs->depthSize, cfgs->stencilSize, cfgs->windowDrawable, cfgs->pbufferDrawable);
4728 /* Yikes we haven't found any suitable formats. This should only happen in case of GDI software rendering which we can't use anyway as its 3D functionality is very, very limited */
4731 ERR("Disabling Direct3D because no hardware accelerated pixel formats have been found!\n");
4733 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
4734 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
4739 /* D16, D24X8 and D24S8 are common depth / depth+stencil formats. All drivers support them though this doesn't
4740 * mean that the format is offered in hardware. For instance Geforce8 cards don't have offer D16 in hardware
4741 * but just fake it using D24(X8?) which is fine. D3D also allows that.
4742 * Some display drivers (i915 on Linux) only report mixed depth+stencil formats like D24S8. MSDN clearly mentions
4743 * that only on lockable formats (e.g. D16_locked) the bit order is guaranteed and that on other formats the
4744 * driver is allowed to consume more bits EXCEPT for stencil bits.
4746 * Mark an adapter with this broken stencil behavior.
4748 adapter->brokenStencil = TRUE;
4749 for (i = 0, cfgs = adapter->cfgs; i < adapter->nCfgs; ++i)
4751 /* Nearly all drivers offer depth formats without stencil, only on i915 this if-statement won't be entered. */
4752 if(cfgs[i].depthSize && !cfgs[i].stencilSize) {
4753 adapter->brokenStencil = FALSE;
4758 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
4760 select_shader_mode(&adapter->gl_info, WINED3DDEVTYPE_HAL, &ps_selected_mode, &vs_selected_mode);
4761 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &adapter->gl_info);
4762 fillGLAttribFuncs(&adapter->gl_info);
4763 adapter->opengl = TRUE;
4765 This->adapter_count = 1;
4766 TRACE("%u adapters successfully initialized\n", This->adapter_count);
4771 /* Initialize an adapter for ddraw-only memory counting */
4772 memset(This->adapters, 0, sizeof(This->adapters));
4773 This->adapters[0].num = 0;
4774 This->adapters[0].opengl = FALSE;
4775 This->adapters[0].monitorPoint.x = -1;
4776 This->adapters[0].monitorPoint.y = -1;
4778 This->adapters[0].driver = "Display";
4779 This->adapters[0].description = "WineD3D DirectDraw Emulation";
4780 if(wined3d_settings.emulated_textureram) {
4781 This->adapters[0].TextureRam = wined3d_settings.emulated_textureram;
4783 This->adapters[0].TextureRam = 8 * 1024 * 1024; /* This is plenty for a DDraw-only card */
4786 initPixelFormatsNoGL(&This->adapters[0].gl_info);
4788 This->adapter_count = 1;
4792 /**********************************************************
4793 * IWineD3D VTbl follows
4794 **********************************************************/
4796 const IWineD3DVtbl IWineD3D_Vtbl =
4799 IWineD3DImpl_QueryInterface,
4800 IWineD3DImpl_AddRef,
4801 IWineD3DImpl_Release,
4803 IWineD3DImpl_GetParent,
4804 IWineD3DImpl_GetAdapterCount,
4805 IWineD3DImpl_RegisterSoftwareDevice,
4806 IWineD3DImpl_GetAdapterMonitor,
4807 IWineD3DImpl_GetAdapterModeCount,
4808 IWineD3DImpl_EnumAdapterModes,
4809 IWineD3DImpl_GetAdapterDisplayMode,
4810 IWineD3DImpl_GetAdapterIdentifier,
4811 IWineD3DImpl_CheckDeviceMultiSampleType,
4812 IWineD3DImpl_CheckDepthStencilMatch,
4813 IWineD3DImpl_CheckDeviceType,
4814 IWineD3DImpl_CheckDeviceFormat,
4815 IWineD3DImpl_CheckDeviceFormatConversion,
4816 IWineD3DImpl_GetDeviceCaps,
4817 IWineD3DImpl_CreateDevice