wined3d: Add GL_ATI_fragment_shader.
[wine/wine64.git] / dlls / wined3d / directx.c
blob8873edc591dc3fa115f806d1a998949d93c9a962
1 /*
2 * IWineD3D implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 /* Compile time diagnostics: */
26 #ifndef DEBUG_SINGLE_MODE
27 /* Set to 1 to force only a single display mode to be exposed: */
28 #define DEBUG_SINGLE_MODE 0
29 #endif
32 #include "config.h"
33 #include <assert.h>
34 #include "wined3d_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
37 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
39 /* The d3d device ID */
40 static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
42 /* Extension detection */
43 static const struct {
44 const char *extension_string;
45 GL_SupportedExt extension;
46 DWORD version;
47 } EXTENSION_MAP[] = {
48 /* APPLE */
49 {"GL_APPLE_client_storage", APPLE_CLIENT_STORAGE, 0 },
50 {"GL_APPLE_fence", APPLE_FENCE, 0 },
51 {"GL_APPLE_flush_render", APPLE_FLUSH_RENDER, 0 },
52 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422, 0 },
53 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS, 0 },
55 /* ATI */
56 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL, 0 },
57 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3, 0 },
58 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE, 0 },
59 {"GL_ATI_envmap_bumpmap", ATI_ENVMAP_BUMPMAP, 0 },
60 {"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER, 0 },
62 /* ARB */
63 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS, 0 },
64 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM, 0 },
65 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER, 0 },
66 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL, 0 },
67 {"GL_ARB_imaging", ARB_IMAGING, 0 },
68 {"GL_ARB_multisample", ARB_MULTISAMPLE, 0 }, /* needs GLX_ARB_MULTISAMPLE as well */
69 {"GL_ARB_multitexture", ARB_MULTITEXTURE, 0 },
70 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY, 0 },
71 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT, 0 },
72 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS, 0 },
73 {"GL_ARB_point_sprite", ARB_POINT_SPRITE, 0 },
74 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP, 0 },
75 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION, 0 },
76 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP, 0 },
77 {"GL_ARB_texture_env_add", ARB_TEXTURE_ENV_ADD, 0 },
78 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE, 0 },
79 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3, 0 },
80 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT, 0 },
81 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT, 0 },
82 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO, 0 },
83 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE, 0 },
84 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND, 0 },
85 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT, 0 },
86 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM, 0 },
87 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER, 0 },
88 {"GL_ARB_shader_objects", ARB_SHADER_OBJECTS, 0 },
90 /* EXT */
91 {"GL_EXT_blend_color", EXT_BLEND_COLOR, 0 },
92 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX, 0 },
93 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE, 0 },
94 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE, 0 },
95 {"GL_EXT_fog_coord", EXT_FOG_COORD, 0 },
96 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT, 0 },
97 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT, 0 },
98 {"GL_EXT_paletted_texture", EXT_PALETTED_TEXTURE, 0 },
99 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS, 0 },
100 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR, 0 },
101 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE, 0 },
102 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP, 0 },
103 {"GL_EXT_texture3D", EXT_TEXTURE3D, MAKEDWORD_VERSION(1, 2) },
104 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC, 0 },
105 {"GL_EXT_texture_env_add", EXT_TEXTURE_ENV_ADD, 0 },
106 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE, 0 },
107 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3, 0 },
108 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB, 0 },
109 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC, 0 },
110 {"GL_EXT_texture_lod", EXT_TEXTURE_LOD, 0 },
111 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS, 0 },
112 {"GL_EXT_vertex_shader", EXT_VERTEX_SHADER, 0 },
113 {"GL_EXT_vertex_weighting", EXT_VERTEX_WEIGHTING, 0 },
114 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS, 0 },
116 /* NV */
117 {"GL_NV_half_float", NV_HALF_FLOAT, 0 },
118 {"GL_NV_fence", NV_FENCE, 0 },
119 {"GL_NV_fog_distance", NV_FOG_DISTANCE, 0 },
120 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM, 0 },
121 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2, 0 },
122 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS, 0 },
123 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2, 0 },
124 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION, 0 },
125 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4, 0 },
126 {"GL_NV_texture_shader", NV_TEXTURE_SHADER, 0 },
127 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2, 0 },
128 {"GL_NV_texture_shader3", NV_TEXTURE_SHADER3, 0 },
129 {"GL_NV_occlusion_query", NV_OCCLUSION_QUERY, 0 },
130 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM, 0 },
131 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1, 0 },
132 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2, 0 },
133 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3, 0 },
134 {"GL_NV_depth_clamp", NV_DEPTH_CLAMP, 0 },
135 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT, 0 },
137 /* SGI */
138 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP, 0 },
141 /**********************************************************
142 * Utility functions follow
143 **********************************************************/
145 /* Adapters */
146 static int numAdapters = 0;
147 static struct WineD3DAdapter Adapters[1];
149 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat);
151 /* lookup tables */
152 int minLookup[MAX_LOOKUPS];
153 int maxLookup[MAX_LOOKUPS];
154 DWORD *stateLookup[MAX_LOOKUPS];
156 DWORD minMipLookup[WINED3DTEXF_ANISOTROPIC + 1][WINED3DTEXF_LINEAR + 1];
158 /* drawStridedSlow attributes */
159 glAttribFunc position_funcs[WINED3DDECLTYPE_UNUSED];
160 glAttribFunc diffuse_funcs[WINED3DDECLTYPE_UNUSED];
161 glAttribFunc specular_funcs[WINED3DDECLTYPE_UNUSED];
162 glAttribFunc normal_funcs[WINED3DDECLTYPE_UNUSED];
163 glTexAttribFunc texcoord_funcs[WINED3DDECLTYPE_UNUSED];
166 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created
167 * ie there is no GL Context - Get a default rendering context to enable the
168 * function query some info from GL
171 static int wined3d_fake_gl_context_ref = 0;
172 static BOOL wined3d_fake_gl_context_foreign;
173 static BOOL wined3d_fake_gl_context_available = FALSE;
174 static HDC wined3d_fake_gl_context_hdc = NULL;
175 static HWND wined3d_fake_gl_context_hwnd = NULL;
177 static CRITICAL_SECTION wined3d_fake_gl_context_cs;
178 static CRITICAL_SECTION_DEBUG wined3d_fake_gl_context_cs_debug =
180 0, 0, &wined3d_fake_gl_context_cs,
181 { &wined3d_fake_gl_context_cs_debug.ProcessLocksList,
182 &wined3d_fake_gl_context_cs_debug.ProcessLocksList },
183 0, 0, { (DWORD_PTR)(__FILE__ ": wined3d_fake_gl_context_cs") }
185 static CRITICAL_SECTION wined3d_fake_gl_context_cs = { &wined3d_fake_gl_context_cs_debug, -1, 0, 0, 0, 0 };
187 static void WineD3D_ReleaseFakeGLContext(void) {
188 HGLRC glCtx;
190 EnterCriticalSection(&wined3d_fake_gl_context_cs);
192 if(!wined3d_fake_gl_context_available) {
193 TRACE_(d3d_caps)("context not available\n");
194 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
195 return;
198 glCtx = pwglGetCurrentContext();
200 TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref);
201 if (0 == (--wined3d_fake_gl_context_ref) ) {
202 if(!wined3d_fake_gl_context_foreign && glCtx) {
203 TRACE_(d3d_caps)("destroying fake GL context\n");
204 pwglMakeCurrent(NULL, NULL);
205 pwglDeleteContext(glCtx);
207 if(wined3d_fake_gl_context_hdc)
208 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
209 wined3d_fake_gl_context_hdc = NULL; /* Make sure we don't think that it is still around */
210 if(wined3d_fake_gl_context_hwnd)
211 DestroyWindow(wined3d_fake_gl_context_hwnd);
212 wined3d_fake_gl_context_hwnd = NULL;
213 wined3d_fake_gl_context_available = FALSE;
215 assert(wined3d_fake_gl_context_ref >= 0);
217 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
220 static BOOL WineD3D_CreateFakeGLContext(void) {
221 HGLRC glCtx = NULL;
223 EnterCriticalSection(&wined3d_fake_gl_context_cs);
225 TRACE("getting context...\n");
226 if(wined3d_fake_gl_context_ref > 0) goto ret;
227 assert(0 == wined3d_fake_gl_context_ref);
229 wined3d_fake_gl_context_foreign = TRUE;
231 glCtx = pwglGetCurrentContext();
232 if (!glCtx) {
233 PIXELFORMATDESCRIPTOR pfd;
234 int iPixelFormat;
236 wined3d_fake_gl_context_foreign = FALSE;
238 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes */
239 wined3d_fake_gl_context_hwnd = CreateWindowA("WineD3D_OpenGL", "WineD3D fake window", WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
240 if(!wined3d_fake_gl_context_hwnd) {
241 ERR("HWND creation failed!\n");
242 goto fail;
244 wined3d_fake_gl_context_hdc = GetDC(wined3d_fake_gl_context_hwnd);
245 if(!wined3d_fake_gl_context_hdc) {
246 ERR("GetDC failed!\n");
247 goto fail;
250 /* PixelFormat selection */
251 ZeroMemory(&pfd, sizeof(pfd));
252 pfd.nSize = sizeof(pfd);
253 pfd.nVersion = 1;
254 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;/*PFD_GENERIC_ACCELERATED*/
255 pfd.iPixelType = PFD_TYPE_RGBA;
256 pfd.cColorBits = 32;
257 pfd.iLayerType = PFD_MAIN_PLANE;
259 iPixelFormat = ChoosePixelFormat(wined3d_fake_gl_context_hdc, &pfd);
260 if(!iPixelFormat) {
261 /* If this happens something is very wrong as ChoosePixelFormat barely fails */
262 ERR("Can't find a suitable iPixelFormat\n");
263 goto fail;
265 DescribePixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, sizeof(pfd), &pfd);
266 SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd);
268 /* Create a GL context */
269 glCtx = pwglCreateContext(wined3d_fake_gl_context_hdc);
270 if (!glCtx) {
271 WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
272 goto fail;
275 /* Make it the current GL context */
276 if (!pwglMakeCurrent(wined3d_fake_gl_context_hdc, glCtx)) {
277 WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
278 goto fail;
282 ret:
283 TRACE("incrementing ref from %i\n", wined3d_fake_gl_context_ref);
284 wined3d_fake_gl_context_ref++;
285 wined3d_fake_gl_context_available = TRUE;
286 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
287 return TRUE;
288 fail:
289 if(wined3d_fake_gl_context_hdc)
290 ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
291 wined3d_fake_gl_context_hdc = NULL;
292 if(wined3d_fake_gl_context_hwnd)
293 DestroyWindow(wined3d_fake_gl_context_hwnd);
294 wined3d_fake_gl_context_hwnd = NULL;
295 if(glCtx) pwglDeleteContext(glCtx);
296 LeaveCriticalSection(&wined3d_fake_gl_context_cs);
297 return FALSE;
300 /* Adjust the amount of used texture memory */
301 long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram){
302 UINT Adapter = D3DDevice->adapterNo;
304 Adapters[Adapter].UsedTextureRam += glram;
305 TRACE("Adjusted gl ram by %ld to %d\n", glram, Adapters[Adapter].UsedTextureRam);
306 return Adapters[Adapter].UsedTextureRam;
309 /**********************************************************
310 * IUnknown parts follows
311 **********************************************************/
313 static HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
315 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
317 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
318 if (IsEqualGUID(riid, &IID_IUnknown)
319 || IsEqualGUID(riid, &IID_IWineD3DBase)
320 || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
321 IUnknown_AddRef(iface);
322 *ppobj = This;
323 return S_OK;
325 *ppobj = NULL;
326 return E_NOINTERFACE;
329 static ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
330 IWineD3DImpl *This = (IWineD3DImpl *)iface;
331 ULONG refCount = InterlockedIncrement(&This->ref);
333 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
334 return refCount;
337 static ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
338 IWineD3DImpl *This = (IWineD3DImpl *)iface;
339 ULONG ref;
340 TRACE("(%p) : Releasing from %d\n", This, This->ref);
341 ref = InterlockedDecrement(&This->ref);
342 if (ref == 0) {
343 HeapFree(GetProcessHeap(), 0, This);
346 return ref;
349 /* Set the shader type for this device, depending on the given capabilities,
350 * the device type, and the user preferences in wined3d_settings */
352 void select_shader_mode(
353 WineD3D_GL_Info *gl_info,
354 WINED3DDEVTYPE DeviceType,
355 int* ps_selected,
356 int* vs_selected) {
358 if (wined3d_settings.vs_mode == VS_NONE) {
359 *vs_selected = SHADER_NONE;
360 } else if (gl_info->supported[ARB_VERTEX_SHADER] && wined3d_settings.glslRequested) {
361 /* Geforce4 cards support GLSL but for vertex shaders only. Further its reported GLSL caps are
362 * wrong. This combined with the fact that glsl won't offer more features or performance, use ARB
363 * shaders only on this card. */
364 if(gl_info->vs_nv_version && gl_info->vs_nv_version < VS_VERSION_20)
365 *vs_selected = SHADER_ARB;
366 else
367 *vs_selected = SHADER_GLSL;
368 } else if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
369 *vs_selected = SHADER_ARB;
370 } else {
371 *vs_selected = SHADER_NONE;
374 if (wined3d_settings.ps_mode == PS_NONE) {
375 *ps_selected = SHADER_NONE;
376 } else if (gl_info->supported[ARB_FRAGMENT_SHADER] && wined3d_settings.glslRequested) {
377 *ps_selected = SHADER_GLSL;
378 } else if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
379 *ps_selected = SHADER_ARB;
380 } else {
381 *ps_selected = SHADER_NONE;
385 /** Select the number of report maximum shader constants based on the selected shader modes */
386 static void select_shader_max_constants(
387 int ps_selected_mode,
388 int vs_selected_mode,
389 WineD3D_GL_Info *gl_info) {
391 switch (vs_selected_mode) {
392 case SHADER_GLSL:
393 /* Subtract the other potential uniforms from the max available (bools, ints, and 1 row of projection matrix) */
394 gl_info->max_vshader_constantsF = gl_info->vs_glsl_constantsF - (MAX_CONST_B / 4) - MAX_CONST_I - 1;
395 break;
396 case SHADER_ARB:
397 /* We have to subtract any other PARAMs that we might use in our shader programs.
398 * ATI seems to count 2 implicit PARAMs when we use fog and NVIDIA counts 1,
399 * and we reference one row of the PROJECTION matrix which counts as 1 PARAM. */
400 gl_info->max_vshader_constantsF = gl_info->vs_arb_constantsF - 3;
401 break;
402 default:
403 gl_info->max_vshader_constantsF = 0;
404 break;
407 switch (ps_selected_mode) {
408 case SHADER_GLSL:
409 /* Subtract the other potential uniforms from the max available (bools & ints), and 2 states for fog.
410 * In theory the texbem instruction may need one more shader constant too. But lets assume
411 * that a sm <= 1.3 shader does not need all the uniforms provided by a glsl-capable card,
412 * and lets not take away a uniform needlessly from all other shaders.
414 gl_info->max_pshader_constantsF = gl_info->ps_glsl_constantsF - (MAX_CONST_B / 4) - MAX_CONST_I - 2;
415 break;
416 case SHADER_ARB:
417 /* The arb shader only loads the bump mapping environment matrix into the shader if it finds
418 * a free constant to do that, so only reduce the number of available constants by 2 for the fog states.
420 gl_info->max_pshader_constantsF = gl_info->ps_arb_constantsF - 2;
421 break;
422 default:
423 gl_info->max_pshader_constantsF = 0;
424 break;
428 /**********************************************************
429 * IWineD3D parts follows
430 **********************************************************/
432 #define GLINFO_LOCATION (*gl_info)
433 static inline BOOL test_arb_vs_offset_limit(WineD3D_GL_Info *gl_info) {
434 GLuint prog;
435 BOOL ret = FALSE;
436 const char *testcode =
437 "!!ARBvp1.0\n"
438 "PARAM C[66] = { program.env[0..65] };\n"
439 "ADDRESS A0;"
440 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
441 "ARL A0.x, zero.x;\n"
442 "MOV result.position, C[A0.x + 65];\n"
443 "END\n";
445 while(glGetError());
446 GL_EXTCALL(glGenProgramsARB(1, &prog));
447 if(!prog) {
448 ERR("Failed to create an ARB offset limit test program\n");
450 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
451 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
452 strlen(testcode), testcode));
453 if(glGetError() != 0) {
454 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
455 TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
456 ret = TRUE;
457 } else TRACE("OpenGL implementation allows offsets > 63\n");
459 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
460 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
461 checkGLcall("ARB vp offset limit test cleanup\n");
463 return ret;
466 static DWORD ver_for_ext(GL_SupportedExt ext)
468 unsigned int i;
469 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
470 if(EXTENSION_MAP[i].extension == ext) {
471 return EXTENSION_MAP[i].version;
474 return 0;
477 BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
478 const char *GL_Extensions = NULL;
479 const char *WGL_Extensions = NULL;
480 const char *gl_string = NULL;
481 const char *gl_string_cursor = NULL;
482 GLint gl_max;
483 GLfloat gl_floatv[2];
484 int major = 1, minor = 0;
485 BOOL return_value = TRUE;
486 unsigned i;
487 HDC hdc;
488 unsigned int vidmem=0;
490 TRACE_(d3d_caps)("(%p)\n", gl_info);
492 ENTER_GL();
494 gl_string = (const char *) glGetString(GL_RENDERER);
495 if (NULL == gl_string)
496 gl_string = "None";
497 strcpy(gl_info->gl_renderer, gl_string);
499 gl_string = (const char *) glGetString(GL_VENDOR);
500 TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
501 if (gl_string != NULL) {
502 /* Fill in the GL vendor */
503 if (strstr(gl_string, "NVIDIA")) {
504 gl_info->gl_vendor = VENDOR_NVIDIA;
505 } else if (strstr(gl_string, "ATI")) {
506 gl_info->gl_vendor = VENDOR_ATI;
507 } else if (strstr(gl_string, "Intel(R)") ||
508 strstr(gl_info->gl_renderer, "Intel(R)") ||
509 strstr(gl_string, "Intel Inc.")) {
510 gl_info->gl_vendor = VENDOR_INTEL;
511 } else if (strstr(gl_string, "Mesa")) {
512 gl_info->gl_vendor = VENDOR_MESA;
513 } else {
514 gl_info->gl_vendor = VENDOR_WINE;
516 } else {
517 gl_info->gl_vendor = VENDOR_WINE;
521 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
523 /* Parse the GL_VERSION field into major and minor information */
524 gl_string = (const char *) glGetString(GL_VERSION);
525 if (gl_string != NULL) {
527 /* First, parse the generic opengl version. This is supposed not to be convoluted with
528 * driver specific information
530 gl_string_cursor = gl_string;
531 major = atoi(gl_string_cursor);
532 if(major <= 0) {
533 ERR("Invalid opengl major version: %d\n", major);
535 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
536 ++gl_string_cursor;
538 if (*gl_string_cursor++ != '.') {
539 ERR_(d3d_caps)("Invalid opengl version string: %s\n", debugstr_a(gl_string));
541 minor = atoi(gl_string_cursor);
542 TRACE_(d3d_caps)("Found OpenGL version: %d.%d\n", major, minor);
543 gl_info->gl_version = MAKEDWORD_VERSION(major, minor);
545 /* Now parse the driver specific string which we'll report to the app */
546 switch (gl_info->gl_vendor) {
547 case VENDOR_NVIDIA:
548 gl_string_cursor = strstr(gl_string, "NVIDIA");
549 if (!gl_string_cursor) {
550 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
551 break;
554 gl_string_cursor = strstr(gl_string_cursor, " ");
555 if (!gl_string_cursor) {
556 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
557 break;
560 while (*gl_string_cursor == ' ') {
561 ++gl_string_cursor;
564 if (!*gl_string_cursor) {
565 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
566 break;
569 major = atoi(gl_string_cursor);
570 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
571 ++gl_string_cursor;
574 if (*gl_string_cursor++ != '.') {
575 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
576 break;
579 minor = atoi(gl_string_cursor);
580 minor = major*100+minor;
581 major = 10;
583 break;
585 case VENDOR_ATI:
586 major = minor = 0;
587 gl_string_cursor = strchr(gl_string, '-');
588 if (gl_string_cursor) {
589 int error = 0;
590 gl_string_cursor++;
592 /* Check if version number is of the form x.y.z */
593 if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
594 error = 1;
595 if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
596 error = 1;
597 if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
598 error = 1;
599 if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
600 error = 1;
602 /* Mark version number as malformed */
603 if (error)
604 gl_string_cursor = 0;
607 if (!gl_string_cursor)
608 WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
609 else {
610 major = *gl_string_cursor - '0';
611 minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
613 break;
615 case VENDOR_INTEL:
616 /* Apple and Mesa version strings look differently, but both provide intel drivers */
617 if(strstr(gl_string, "APPLE")) {
618 /* [0-9]+.[0-9]+ APPLE-[0-9]+.[0.9]+.[0.9]+
619 * We only need the first part, and use the APPLE as identification
620 * "1.2 APPLE-1.4.56"
622 gl_string_cursor = gl_string;
623 major = atoi(gl_string_cursor);
624 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
625 ++gl_string_cursor;
628 if (*gl_string_cursor++ != '.') {
629 ERR_(d3d_caps)("Invalid MacOS-Intel version string: %s\n", debugstr_a(gl_string));
630 break;
633 minor = atoi(gl_string_cursor);
634 break;
637 case VENDOR_MESA:
638 gl_string_cursor = strstr(gl_string, "Mesa");
639 gl_string_cursor = strstr(gl_string_cursor, " ");
640 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
641 if (*gl_string_cursor) {
642 char tmp[16];
643 int cursor = 0;
645 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
646 tmp[cursor++] = *gl_string_cursor;
647 ++gl_string_cursor;
649 tmp[cursor] = 0;
650 major = atoi(tmp);
652 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
653 ++gl_string_cursor;
655 cursor = 0;
656 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
657 tmp[cursor++] = *gl_string_cursor;
658 ++gl_string_cursor;
660 tmp[cursor] = 0;
661 minor = atoi(tmp);
663 break;
665 default:
666 major = 0;
667 minor = 9;
669 gl_info->driver_version = MAKEDWORD_VERSION(major, minor);
670 TRACE_(d3d_caps)("found driver version (%s)->%i.%i->(0x%08x)\n", debugstr_a(gl_string), major, minor, gl_info->driver_version);
671 /* Current Windows drivers have versions like 6.14.... (some older have an earlier version) */
672 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
673 } else {
674 FIXME("OpenGL driver did not return version information\n");
675 gl_info->driver_version = MAKEDWORD_VERSION(0, 0);
676 gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
679 TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
682 * Initialize openGL extension related variables
683 * with Default values
685 memset(&gl_info->supported, 0, sizeof(gl_info->supported));
686 gl_info->max_buffers = 1;
687 gl_info->max_textures = 1;
688 gl_info->max_texture_stages = 1;
689 gl_info->max_fragment_samplers = 1;
690 gl_info->max_vertex_samplers = 0;
691 gl_info->max_combined_samplers = 0;
692 gl_info->max_sampler_stages = 1;
693 gl_info->ps_arb_version = PS_VERSION_NOT_SUPPORTED;
694 gl_info->ps_arb_max_temps = 0;
695 gl_info->ps_arb_max_instructions = 0;
696 gl_info->vs_arb_version = VS_VERSION_NOT_SUPPORTED;
697 gl_info->vs_arb_max_temps = 0;
698 gl_info->vs_arb_max_instructions = 0;
699 gl_info->vs_nv_version = VS_VERSION_NOT_SUPPORTED;
700 gl_info->vs_ati_version = VS_VERSION_NOT_SUPPORTED;
701 gl_info->vs_glsl_constantsF = 0;
702 gl_info->ps_glsl_constantsF = 0;
703 gl_info->vs_arb_constantsF = 0;
704 gl_info->ps_arb_constantsF = 0;
706 /* Retrieve opengl defaults */
707 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
708 gl_info->max_clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
709 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
711 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
712 gl_info->max_lights = gl_max;
713 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
715 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
716 gl_info->max_texture_size = gl_max;
717 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
719 glGetFloatv(GL_POINT_SIZE_RANGE, gl_floatv);
720 gl_info->max_pointsizemin = gl_floatv[0];
721 gl_info->max_pointsize = gl_floatv[1];
722 TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
724 glGetIntegerv(GL_AUX_BUFFERS, &gl_max);
725 gl_info->max_aux_buffers = gl_max;
726 TRACE_(d3d_caps)("Offscreen rendering support - number of aux buffers=%d\n", gl_max);
728 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
729 GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
730 TRACE_(d3d_caps)("GL_Extensions reported:\n");
732 if (NULL == GL_Extensions) {
733 ERR(" GL_Extensions returns NULL\n");
734 } else {
735 while (*GL_Extensions != 0x00) {
736 const char *Start;
737 char ThisExtn[256];
738 size_t len;
740 while (isspace(*GL_Extensions)) GL_Extensions++;
741 Start = GL_Extensions;
742 while (!isspace(*GL_Extensions) && *GL_Extensions != 0x00) {
743 GL_Extensions++;
746 len = GL_Extensions - Start;
747 if (len == 0 || len >= sizeof(ThisExtn))
748 continue;
750 memcpy(ThisExtn, Start, len);
751 ThisExtn[len] = '\0';
752 TRACE_(d3d_caps)("- %s\n", ThisExtn);
754 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
755 if (!strcmp(ThisExtn, EXTENSION_MAP[i].extension_string)) {
756 TRACE_(d3d_caps)(" FOUND: %s support\n", EXTENSION_MAP[i].extension_string);
757 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
758 break;
762 /* Now work out what GL support this card really has */
763 #define USE_GL_FUNC(type, pfn, ext, replace) { \
764 DWORD ver = ver_for_ext(ext); \
765 if(gl_info->supported[ext]) gl_info->pfn = (type) pwglGetProcAddress(#pfn); \
766 else if(ver && ver <= gl_info->gl_version) gl_info->pfn = (type) pwglGetProcAddress(#replace); \
767 else gl_info->pfn = NULL; \
769 GL_EXT_FUNCS_GEN;
770 #undef USE_GL_FUNC
772 #define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type) pwglGetProcAddress(#pfn);
773 WGL_EXT_FUNCS_GEN;
774 #undef USE_GL_FUNC
776 /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
777 * loading the functions, otherwise the code above will load the extension entry points instead of the
778 * core functions, which may not work
780 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
781 if (gl_info->supported[EXTENSION_MAP[i].extension] == FALSE &&
782 EXTENSION_MAP[i].version <= gl_info->gl_version && EXTENSION_MAP[i].version) {
783 TRACE_(d3d_caps)(" GL CORE: %s support\n", EXTENSION_MAP[i].extension_string);
784 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
788 if (gl_info->supported[APPLE_FENCE]) {
789 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
790 * The apple extension interacts with some other apple exts. Disable the NV
791 * extension if the apple one is support to prevent confusion in other parts
792 * of the code
794 gl_info->supported[NV_FENCE] = FALSE;
796 if (gl_info->supported[APPLE_FLOAT_PIXELS]) {
797 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
799 * The enums are the same:
800 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881A
801 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881B
802 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
803 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
804 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140B
806 if(!gl_info->supported[ARB_TEXTURE_FLOAT]) {
807 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels\n");
808 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
810 if(!gl_info->supported[ARB_HALF_FLOAT_PIXEL]) {
811 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels\n");
812 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
815 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) {
816 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
817 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
819 if (gl_info->supported[NV_TEXTURE_SHADER2]) {
820 /* GL_ATI_envmap_bumpmap won't play nice with texture shaders, so disable it
821 * Won't occur in any real world situation though
823 gl_info->supported[ATI_ENVMAP_BUMPMAP] = FALSE;
825 if (gl_info->supported[ARB_DRAW_BUFFERS]) {
826 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
827 gl_info->max_buffers = gl_max;
828 TRACE_(d3d_caps)("Max draw buffers: %u\n", gl_max);
830 if (gl_info->supported[ARB_MULTITEXTURE]) {
831 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
832 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
833 TRACE_(d3d_caps)("Max textures: %d\n", gl_info->max_textures);
835 if (gl_info->supported[NV_REGISTER_COMBINERS]) {
836 GLint tmp;
837 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &tmp);
838 gl_info->max_texture_stages = min(MAX_TEXTURES, tmp);
839 } else {
840 gl_info->max_texture_stages = min(MAX_TEXTURES, gl_max);
842 TRACE_(d3d_caps)("Max texture stages: %d\n", gl_info->max_texture_stages);
844 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
845 GLint tmp;
846 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
847 gl_info->max_fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
848 } else {
849 gl_info->max_fragment_samplers = max(gl_info->max_fragment_samplers, gl_max);
851 TRACE_(d3d_caps)("Max fragment samplers: %d\n", gl_info->max_fragment_samplers);
853 if (gl_info->supported[ARB_VERTEX_SHADER]) {
854 GLint tmp;
855 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
856 gl_info->max_vertex_samplers = tmp;
857 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
858 gl_info->max_combined_samplers = tmp;
860 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
861 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
862 * an issue because then the sampler setup only depends on the two shaders. If a pixel
863 * shader is used with fixed function vertex processing we're fine too because fixed function
864 * vertex processing doesn't use any samplers. If fixed function fragment processing is
865 * used we have to make sure that all vertex sampler setups are valid together with all
866 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
867 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
868 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
869 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
870 * a fixed function pipeline anymore.
872 * So this is just a check to check that our assumption holds true. If not, write a warning
873 * and reduce the number of vertex samplers or probably disable vertex texture fetch.
875 if(gl_info->max_vertex_samplers &&
876 MAX_TEXTURES + gl_info->max_vertex_samplers > gl_info->max_combined_samplers) {
877 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers\n",
878 gl_info->max_vertex_samplers, gl_info->max_combined_samplers);
879 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers\n");
880 if( gl_info->max_combined_samplers > MAX_TEXTURES )
881 gl_info->max_vertex_samplers =
882 gl_info->max_combined_samplers - MAX_TEXTURES;
883 else
884 gl_info->max_vertex_samplers = 0;
886 } else {
887 gl_info->max_combined_samplers = gl_info->max_fragment_samplers;
889 TRACE_(d3d_caps)("Max vertex samplers: %u\n", gl_info->max_vertex_samplers);
890 TRACE_(d3d_caps)("Max combined samplers: %u\n", gl_info->max_combined_samplers);
892 if (gl_info->supported[ARB_VERTEX_BLEND]) {
893 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
894 gl_info->max_blends = gl_max;
895 TRACE_(d3d_caps)("Max blends: %u\n", gl_info->max_blends);
897 if (gl_info->supported[EXT_TEXTURE3D]) {
898 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
899 gl_info->max_texture3d_size = gl_max;
900 TRACE_(d3d_caps)("Max texture3D size: %d\n", gl_info->max_texture3d_size);
902 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC]) {
903 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
904 gl_info->max_anisotropy = gl_max;
905 TRACE_(d3d_caps)("Max anisotropy: %d\n", gl_info->max_anisotropy);
907 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
908 gl_info->ps_arb_version = PS_VERSION_11;
909 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
910 gl_info->ps_arb_constantsF = gl_max;
911 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d\n", gl_info->ps_arb_constantsF);
912 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
913 gl_info->ps_arb_max_temps = gl_max;
914 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d\n", gl_info->ps_arb_max_temps);
915 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
916 gl_info->ps_arb_max_instructions = gl_max;
917 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d\n", gl_info->ps_arb_max_instructions);
919 if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
920 gl_info->vs_arb_version = VS_VERSION_11;
921 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
922 gl_info->vs_arb_constantsF = gl_max;
923 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d\n", gl_info->vs_arb_constantsF);
924 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
925 gl_info->vs_arb_max_temps = gl_max;
926 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d\n", gl_info->vs_arb_max_temps);
927 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
928 gl_info->vs_arb_max_instructions = gl_max;
929 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d\n", gl_info->vs_arb_max_instructions);
931 gl_info->arb_vs_offset_limit = test_arb_vs_offset_limit(gl_info);
933 if (gl_info->supported[ARB_VERTEX_SHADER]) {
934 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
935 gl_info->vs_glsl_constantsF = gl_max / 4;
936 TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u\n", gl_info->vs_glsl_constantsF);
938 if (gl_info->supported[ARB_FRAGMENT_SHADER]) {
939 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
940 gl_info->ps_glsl_constantsF = gl_max / 4;
941 TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u\n", gl_info->ps_glsl_constantsF);
942 glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
943 gl_info->max_glsl_varyings = gl_max;
944 TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings)\n", gl_max, gl_max / 4);
946 if (gl_info->supported[EXT_VERTEX_SHADER]) {
947 gl_info->vs_ati_version = VS_VERSION_11;
949 if (gl_info->supported[NV_VERTEX_PROGRAM3]) {
950 gl_info->vs_nv_version = VS_VERSION_30;
951 } else if (gl_info->supported[NV_VERTEX_PROGRAM2]) {
952 gl_info->vs_nv_version = VS_VERSION_20;
953 } else if (gl_info->supported[NV_VERTEX_PROGRAM1_1]) {
954 gl_info->vs_nv_version = VS_VERSION_11;
955 } else if (gl_info->supported[NV_VERTEX_PROGRAM]) {
956 gl_info->vs_nv_version = VS_VERSION_10;
958 if (gl_info->supported[NV_FRAGMENT_PROGRAM2]) {
959 gl_info->ps_nv_version = PS_VERSION_30;
960 } else if (gl_info->supported[NV_FRAGMENT_PROGRAM]) {
961 gl_info->ps_nv_version = PS_VERSION_20;
963 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT]) {
964 glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->max_shininess);
965 } else {
966 gl_info->max_shininess = 128.0;
968 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO]) {
969 /* If we have full NP2 texture support, disable GL_ARB_texture_rectangle because we will never use it.
970 * This saves a few redundant glDisable calls
972 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
976 checkGLcall("extension detection\n");
978 /* In some cases the number of texture stages can be larger than the number
979 * of samplers. The GF4 for example can use only 2 samplers (no fragment
980 * shaders), but 8 texture stages (register combiners). */
981 gl_info->max_sampler_stages = max(gl_info->max_fragment_samplers, gl_info->max_texture_stages);
983 /* We can only use ORM_FBO when the hardware supports it. */
984 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && !gl_info->supported[EXT_FRAMEBUFFER_OBJECT]) {
985 WARN_(d3d_caps)("GL_EXT_framebuffer_object not supported, falling back to PBuffer offscreen rendering mode.\n");
986 wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
989 /* MRTs are currently only supported when FBOs are used. */
990 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) {
991 gl_info->max_buffers = 1;
994 /* Below is a list of Nvidia and ATI GPUs. Both vendors have dozens of different GPUs with roughly the same
995 * features. In most cases GPUs from a certain family differ in clockspeeds, the amount of video memory and
996 * in case of the latest videocards in the number of pixel/vertex pipelines.
998 * A Direct3D device object contains the PCI id (vendor + device) of the videocard which is used for
999 * rendering. Various games use this information to get a rough estimation of the features of the card
1000 * and some might use it for enabling 3d effects only on certain types of videocards. In some cases
1001 * games might even use it to work around bugs which happen on certain videocards/driver combinations.
1002 * The problem is that OpenGL only exposes a rendering string containing the name of the videocard and
1003 * not the PCI id.
1005 * Various games depend on the PCI id, so somehow we need to provide one. A simple option is to parse
1006 * the renderer string and translate this to the right PCI id. This is a lot of work because there are more
1007 * than 200 GPUs just for Nvidia. Various cards share the same renderer string, so the amount of code might
1008 * be 'small' but there are quite a number of exceptions which would make this a pain to maintain.
1009 * Another way would be to query the PCI id from the operating system (assuming this is the videocard which
1010 * is used for rendering which is not always the case). This would work but it is not very portable. Second
1011 * it would not work well in, let's say, a remote X situation in which the amount of 3d features which can be used
1012 * is limited.
1014 * As said most games only use the PCI id to get an indication of the capabilities of the card.
1015 * It doesn't really matter if the given id is the correct one if we return the id of a card with
1016 * similar 3d features.
1018 * The code below checks the OpenGL capabilities of a videocard and matches that to a certain level of
1019 * Direct3D functionality. Once a card passes the Direct3D9 check, we know that the card (in case of Nvidia)
1020 * is at least a GeforceFX. To give a better estimate we do a basic check on the renderer string but if that
1021 * won't pass we return a default card. This way is better than maintaining a full card database as even
1022 * without a full database we can return a card with similar features. Second the size of the database
1023 * can be made quite small because when you know what type of 3d functionality a card has, you know to which
1024 * GPU family the GPU must belong. Because of this you only have to check a small part of the renderer string
1025 * to distinguishes between different models from that family.
1027 * The code also selects a default amount of video memory which we will use for an estimation of the amount
1028 * of free texture memory. In case of real D3D the amount of texture memory includes video memory and system
1029 * memory (to be specific AGP memory or in case of PCIE TurboCache/HyperMemory). We don't know how much
1030 * system memory can be addressed by the system but we can make a reasonable estimation about the amount of
1031 * video memory. If the value is slightly wrong it doesn't matter as we didn't include AGP-like memory which
1032 * makes the amount of addressable memory higher and second OpenGL isn't that critical it moves to system
1033 * memory behind our backs if really needed.
1034 * Note that the amount of video memory can be overruled using a registry setting.
1036 switch (gl_info->gl_vendor) {
1037 case VENDOR_NVIDIA:
1038 /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1039 * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1041 if(WINE_D3D9_CAPABLE(gl_info) && (gl_info->vs_nv_version == VS_VERSION_30)) {
1042 /* Geforce8 - highend */
1043 if (strstr(gl_info->gl_renderer, "8800")) {
1044 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8800GTS;
1045 vidmem = 320; /* The 8800GTS uses 320MB, a 8800GTX can have 768MB */
1047 /* Geforce8 - midend mobile */
1048 else if(strstr(gl_info->gl_renderer, "8600 M")) {
1049 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600MGT;
1050 vidmem = 512;
1052 /* Geforce8 - midend */
1053 else if(strstr(gl_info->gl_renderer, "8600") ||
1054 strstr(gl_info->gl_renderer, "8700"))
1056 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600GT;
1057 vidmem = 256;
1059 /* Geforce8 - lowend */
1060 else if(strstr(gl_info->gl_renderer, "8300") ||
1061 strstr(gl_info->gl_renderer, "8400") ||
1062 strstr(gl_info->gl_renderer, "8500"))
1064 gl_info->gl_card = CARD_NVIDIA_GEFORCE_8300GS;
1065 vidmem = 128; /* 128-256MB for a 8300, 256-512MB for a 8400 */
1067 /* Geforce7 - highend */
1068 else if(strstr(gl_info->gl_renderer, "7800") ||
1069 strstr(gl_info->gl_renderer, "7900") ||
1070 strstr(gl_info->gl_renderer, "7950") ||
1071 strstr(gl_info->gl_renderer, "Quadro FX 4") ||
1072 strstr(gl_info->gl_renderer, "Quadro FX 5"))
1074 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7800GT;
1075 vidmem = 256; /* A 7800GT uses 256MB while highend 7900 cards can use 512MB */
1077 /* Geforce7 midend */
1078 else if(strstr(gl_info->gl_renderer, "7600") ||
1079 strstr(gl_info->gl_renderer, "7700")) {
1080 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7600;
1081 vidmem = 256; /* The 7600 uses 256-512MB */
1082 /* Geforce7 lower medium */
1083 } else if(strstr(gl_info->gl_renderer, "7400")) {
1084 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7400;
1085 vidmem = 256; /* The 7400 uses 256-512MB */
1087 /* Geforce7 lowend */
1088 else if(strstr(gl_info->gl_renderer, "7300")) {
1089 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7300;
1090 vidmem = 256; /* Mac Pros with this card have 256 MB */
1092 /* Geforce6 highend */
1093 else if(strstr(gl_info->gl_renderer, "6800"))
1095 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6800;
1096 vidmem = 128; /* The 6800 uses 128-256MB, the 7600 uses 256-512MB */
1098 /* Geforce6 - midend */
1099 else if(strstr(gl_info->gl_renderer, "6600") ||
1100 strstr(gl_info->gl_renderer, "6610") ||
1101 strstr(gl_info->gl_renderer, "6700"))
1103 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6600GT;
1104 vidmem = 128; /* A 6600GT has 128-256MB */
1106 /* Geforce6/7 lowend */
1107 else {
1108 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
1109 vidmem = 64; /* */
1111 } else if(WINE_D3D9_CAPABLE(gl_info)) {
1112 /* GeforceFX - highend */
1113 if (strstr(gl_info->gl_renderer, "5800") ||
1114 strstr(gl_info->gl_renderer, "5900") ||
1115 strstr(gl_info->gl_renderer, "5950") ||
1116 strstr(gl_info->gl_renderer, "Quadro FX"))
1118 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5800;
1119 vidmem = 256; /* 5800-5900 cards use 256MB */
1121 /* GeforceFX - midend */
1122 else if(strstr(gl_info->gl_renderer, "5600") ||
1123 strstr(gl_info->gl_renderer, "5650") ||
1124 strstr(gl_info->gl_renderer, "5700") ||
1125 strstr(gl_info->gl_renderer, "5750"))
1127 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1128 vidmem = 128; /* A 5600 uses 128-256MB */
1130 /* GeforceFX - lowend */
1131 else {
1132 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1133 vidmem = 64; /* Normal FX5200 cards use 64-256MB; laptop (non-standard) can have less */
1135 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1136 if (strstr(gl_info->gl_renderer, "GeForce4 Ti") || strstr(gl_info->gl_renderer, "Quadro4")) {
1137 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1138 vidmem = 64; /* Geforce4 Ti cards have 64-128MB */
1140 else {
1141 gl_info->gl_card = CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1142 vidmem = 64; /* Geforce3 cards have 64-128MB */
1144 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1145 if (strstr(gl_info->gl_renderer, "GeForce4 MX")) {
1146 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1147 vidmem = 64; /* Most Geforce4MX GPUs have at least 64MB of memory, some early models had 32MB but most have 64MB or even 128MB */
1149 else if(strstr(gl_info->gl_renderer, "GeForce2 MX") || strstr(gl_info->gl_renderer, "Quadro2 MXR")) {
1150 gl_info->gl_card = CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1151 vidmem = 32; /* Geforce2MX GPUs have 32-64MB of video memory */
1153 else if(strstr(gl_info->gl_renderer, "GeForce2") || strstr(gl_info->gl_renderer, "Quadro2")) {
1154 gl_info->gl_card = CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1155 vidmem = 32; /* Geforce2 GPUs have 32-64MB of video memory */
1157 else {
1158 gl_info->gl_card = CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1159 vidmem = 32; /* Most Geforce1 cards have 32MB, there are also some rare 16 and 64MB (Dell) models */
1161 } else {
1162 if (strstr(gl_info->gl_renderer, "TNT2")) {
1163 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1164 vidmem = 32; /* Most TNT2 boards have 32MB, though there are 16MB boards too */
1166 else {
1167 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1168 vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
1171 break;
1172 case VENDOR_ATI:
1173 if(WINE_D3D9_CAPABLE(gl_info)) {
1174 /* Radeon R6xx HD2900 - highend */
1175 if (strstr(gl_info->gl_renderer, "HD 2900")) {
1176 gl_info->gl_card = CARD_ATI_RADEON_HD2900;
1177 vidmem = 512; /* HD2900 uses 512-1024MB */
1179 /* Radeon R6xx HD2600- midend */
1180 else if (strstr(gl_info->gl_renderer, "HD 2600")) {
1181 gl_info->gl_card = CARD_ATI_RADEON_HD2600;
1182 vidmem = 256; /* HD2600 uses 256-512MB */
1184 /* Radeon R6xx HD2300/HD2400 - lowend */
1185 else if (strstr(gl_info->gl_renderer, "HD 2300") ||
1186 strstr(gl_info->gl_renderer, "HD 2400"))
1188 gl_info->gl_card = CARD_ATI_RADEON_HD2300;
1189 vidmem = 128; /* HD2300 uses at least 128MB, HD2400 uses 256MB */
1191 /* Radeon R5xx */
1192 else if (strstr(gl_info->gl_renderer, "X1600") ||
1193 strstr(gl_info->gl_renderer, "X1650") ||
1194 strstr(gl_info->gl_renderer, "X1800") ||
1195 strstr(gl_info->gl_renderer, "X1900") ||
1196 strstr(gl_info->gl_renderer, "X1950"))
1198 gl_info->gl_card = CARD_ATI_RADEON_X1600;
1199 vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
1201 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
1202 else if(strstr(gl_info->gl_renderer, "X700") ||
1203 strstr(gl_info->gl_renderer, "X800") ||
1204 strstr(gl_info->gl_renderer, "X850") ||
1205 strstr(gl_info->gl_renderer, "X1300") ||
1206 strstr(gl_info->gl_renderer, "X1400") ||
1207 strstr(gl_info->gl_renderer, "X1450") ||
1208 strstr(gl_info->gl_renderer, "X1550"))
1210 gl_info->gl_card = CARD_ATI_RADEON_X700;
1211 vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
1213 /* Radeon R3xx */
1214 else {
1215 gl_info->gl_card = CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
1216 vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
1218 } else if(WINE_D3D8_CAPABLE(gl_info)) {
1219 gl_info->gl_card = CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
1220 vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
1221 } else if(WINE_D3D7_CAPABLE(gl_info)) {
1222 gl_info->gl_card = CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
1223 vidmem = 32; /* There are models with up to 64MB */
1224 } else {
1225 gl_info->gl_card = CARD_ATI_RAGE_128PRO;
1226 vidmem = 16; /* There are 16-32MB models */
1228 break;
1229 case VENDOR_INTEL:
1230 if (strstr(gl_info->gl_renderer, "GMA 950")) {
1231 /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */
1232 gl_info->gl_card = CARD_INTEL_I945GM;
1233 vidmem = 64;
1234 } else if (strstr(gl_info->gl_renderer, "915GM")) {
1235 gl_info->gl_card = CARD_INTEL_I915GM;
1236 } else if (strstr(gl_info->gl_renderer, "915G")) {
1237 gl_info->gl_card = CARD_INTEL_I915G;
1238 } else if (strstr(gl_info->gl_renderer, "865G")) {
1239 gl_info->gl_card = CARD_INTEL_I865G;
1240 } else if (strstr(gl_info->gl_renderer, "855G")) {
1241 gl_info->gl_card = CARD_INTEL_I855G;
1242 } else if (strstr(gl_info->gl_renderer, "830G")) {
1243 gl_info->gl_card = CARD_INTEL_I830G;
1244 } else {
1245 gl_info->gl_card = CARD_INTEL_I915G;
1247 break;
1248 case VENDOR_MESA:
1249 case VENDOR_WINE:
1250 default:
1251 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice
1252 * for Nvidia was because the hardware and drivers they make are of good quality. This makes
1253 * them a good generic choice.
1255 gl_info->gl_vendor = VENDOR_NVIDIA;
1256 if(WINE_D3D9_CAPABLE(gl_info))
1257 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
1258 else if(WINE_D3D8_CAPABLE(gl_info))
1259 gl_info->gl_card = CARD_NVIDIA_GEFORCE3;
1260 else if(WINE_D3D7_CAPABLE(gl_info))
1261 gl_info->gl_card = CARD_NVIDIA_GEFORCE;
1262 else if(WINE_D3D6_CAPABLE(gl_info))
1263 gl_info->gl_card = CARD_NVIDIA_RIVA_TNT;
1264 else
1265 gl_info->gl_card = CARD_NVIDIA_RIVA_128;
1267 TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card);
1269 /* If we have an estimate use it, else default to 64MB; */
1270 if(vidmem)
1271 gl_info->vidmem = vidmem*1024*1024; /* convert from MBs to bytes */
1272 else
1273 gl_info->vidmem = WINE_DEFAULT_VIDMEM;
1275 /* Load all the lookup tables
1276 TODO: It may be a good idea to make minLookup and maxLookup const and populate them in wined3d_private.h where they are declared */
1277 minLookup[WINELOOKUP_WARPPARAM] = WINED3DTADDRESS_WRAP;
1278 maxLookup[WINELOOKUP_WARPPARAM] = WINED3DTADDRESS_MIRRORONCE;
1280 minLookup[WINELOOKUP_MAGFILTER] = WINED3DTEXF_NONE;
1281 maxLookup[WINELOOKUP_MAGFILTER] = WINED3DTEXF_ANISOTROPIC;
1284 for (i = 0; i < MAX_LOOKUPS; i++) {
1285 stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
1288 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
1289 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
1290 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1291 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1292 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1293 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1294 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
1295 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
1296 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
1297 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
1299 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_NONE - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
1300 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_POINT - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
1301 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_LINEAR - minLookup[WINELOOKUP_MAGFILTER]] = GL_LINEAR;
1302 stateLookup[WINELOOKUP_MAGFILTER][WINED3DTEXF_ANISOTROPIC - minLookup[WINELOOKUP_MAGFILTER]] =
1303 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR : GL_NEAREST;
1306 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_NONE] = GL_LINEAR;
1307 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_POINT] = GL_LINEAR;
1308 minMipLookup[WINED3DTEXF_NONE][WINED3DTEXF_LINEAR] = GL_LINEAR;
1309 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_NONE] = GL_NEAREST;
1310 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_POINT] = GL_NEAREST_MIPMAP_NEAREST;
1311 minMipLookup[WINED3DTEXF_POINT][WINED3DTEXF_LINEAR] = GL_NEAREST_MIPMAP_LINEAR;
1312 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_NONE] = GL_LINEAR;
1313 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_POINT] = GL_LINEAR_MIPMAP_NEAREST;
1314 minMipLookup[WINED3DTEXF_LINEAR][WINED3DTEXF_LINEAR] = GL_LINEAR_MIPMAP_LINEAR;
1315 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_NONE] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ?
1316 GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1317 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_POINT] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR;
1318 minMipLookup[WINED3DTEXF_ANISOTROPIC][WINED3DTEXF_LINEAR] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
1320 /* TODO: config lookups */
1322 /* Make sure there's an active HDC else the WGL extensions will fail */
1323 hdc = pwglGetCurrentDC();
1324 if (hdc) {
1325 WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc));
1326 TRACE_(d3d_caps)("WGL_Extensions reported:\n");
1328 if (NULL == WGL_Extensions) {
1329 ERR(" WGL_Extensions returns NULL\n");
1330 } else {
1331 while (*WGL_Extensions != 0x00) {
1332 const char *Start;
1333 char ThisExtn[256];
1334 size_t len;
1336 while (isspace(*WGL_Extensions)) WGL_Extensions++;
1337 Start = WGL_Extensions;
1338 while (!isspace(*WGL_Extensions) && *WGL_Extensions != 0x00) {
1339 WGL_Extensions++;
1342 len = WGL_Extensions - Start;
1343 if (len == 0 || len >= sizeof(ThisExtn))
1344 continue;
1346 memcpy(ThisExtn, Start, len);
1347 ThisExtn[len] = '\0';
1348 TRACE_(d3d_caps)("- %s\n", ThisExtn);
1350 if (!strcmp(ThisExtn, "WGL_ARB_pbuffer")) {
1351 gl_info->supported[WGL_ARB_PBUFFER] = TRUE;
1352 TRACE_(d3d_caps)("FOUND: WGL_ARB_pbuffer support\n");
1357 LEAVE_GL();
1359 return return_value;
1361 #undef GLINFO_LOCATION
1363 /**********************************************************
1364 * IWineD3D implementation follows
1365 **********************************************************/
1367 static UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
1368 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1370 TRACE_(d3d_caps)("(%p): Reporting %d adapters\n", This, numAdapters);
1371 return numAdapters;
1374 static HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
1375 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1376 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
1377 return WINED3D_OK;
1380 static HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
1381 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1383 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
1384 return NULL;
1387 TRACE_(d3d_caps)("(%p)->(%d)\n", This, Adapter);
1388 return MonitorFromPoint(Adapters[Adapter].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
1391 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
1392 of the same bpp but different resolutions */
1394 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1395 static UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
1396 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1397 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
1399 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1400 return 0;
1403 /* TODO: Store modes per adapter and read it from the adapter structure */
1404 if (Adapter == 0) { /* Display */
1405 int i = 0;
1406 int j = 0;
1408 if (!DEBUG_SINGLE_MODE) {
1409 DEVMODEW DevModeW;
1411 ZeroMemory(&DevModeW, sizeof(DevModeW));
1412 DevModeW.dmSize = sizeof(DevModeW);
1413 while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
1414 j++;
1415 switch (Format)
1417 case WINED3DFMT_UNKNOWN:
1418 /* This is for D3D8, do not enumerate P8 here */
1419 if (DevModeW.dmBitsPerPel == 32 ||
1420 DevModeW.dmBitsPerPel == 16) i++;
1421 break;
1422 case WINED3DFMT_X8R8G8B8:
1423 if (DevModeW.dmBitsPerPel == 32) i++;
1424 break;
1425 case WINED3DFMT_R5G6B5:
1426 if (DevModeW.dmBitsPerPel == 16) i++;
1427 break;
1428 case WINED3DFMT_P8:
1429 if (DevModeW.dmBitsPerPel == 8) i++;
1430 break;
1431 default:
1432 /* Skip other modes as they do not match the requested format */
1433 break;
1436 } else {
1437 i = 1;
1438 j = 1;
1441 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
1442 return i;
1443 } else {
1444 FIXME_(d3d_caps)("Adapter not primary display\n");
1446 return 0;
1449 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1450 static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, WINED3DDISPLAYMODE* pMode) {
1451 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1452 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
1454 /* Validate the parameters as much as possible */
1455 if (NULL == pMode ||
1456 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
1457 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
1458 return WINED3DERR_INVALIDCALL;
1461 /* TODO: Store modes per adapter and read it from the adapter structure */
1462 if (Adapter == 0 && !DEBUG_SINGLE_MODE) { /* Display */
1463 DEVMODEW DevModeW;
1464 int ModeIdx = 0;
1465 int i = 0;
1466 int j = 0;
1468 ZeroMemory(&DevModeW, sizeof(DevModeW));
1469 DevModeW.dmSize = sizeof(DevModeW);
1471 /* If we are filtering to a specific format (D3D9), then need to skip
1472 all unrelated modes, but if mode is irrelevant (D3D8), then we can
1473 just count through the ones with valid bit depths */
1474 while ((i<=Mode) && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0)) {
1475 switch (Format)
1477 case WINED3DFMT_UNKNOWN:
1478 /* This is D3D8. Do not enumerate P8 here */
1479 if (DevModeW.dmBitsPerPel == 32 ||
1480 DevModeW.dmBitsPerPel == 16) i++;
1481 break;
1482 case WINED3DFMT_X8R8G8B8:
1483 if (DevModeW.dmBitsPerPel == 32) i++;
1484 break;
1485 case WINED3DFMT_R5G6B5:
1486 if (DevModeW.dmBitsPerPel == 16) i++;
1487 break;
1488 case WINED3DFMT_P8:
1489 if (DevModeW.dmBitsPerPel == 8) i++;
1490 break;
1491 default:
1492 /* Modes that don't match what we support can get an early-out */
1493 TRACE_(d3d_caps)("Searching for %s, returning D3DERR_INVALIDCALL\n", debug_d3dformat(Format));
1494 return WINED3DERR_INVALIDCALL;
1498 if (i == 0) {
1499 TRACE_(d3d_caps)("No modes found for format (%x - %s)\n", Format, debug_d3dformat(Format));
1500 return WINED3DERR_INVALIDCALL;
1502 ModeIdx = j - 1;
1504 /* Now get the display mode via the calculated index */
1505 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0)) {
1506 pMode->Width = DevModeW.dmPelsWidth;
1507 pMode->Height = DevModeW.dmPelsHeight;
1508 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1509 if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
1510 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1512 if (Format == WINED3DFMT_UNKNOWN) {
1513 pMode->Format = pixelformat_for_depth(DevModeW.dmBitsPerPel);
1514 } else {
1515 pMode->Format = Format;
1517 } else {
1518 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
1519 return WINED3DERR_INVALIDCALL;
1522 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
1523 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format),
1524 DevModeW.dmBitsPerPel);
1526 } else if (DEBUG_SINGLE_MODE) {
1527 /* Return one setting of the format requested */
1528 if (Mode > 0) return WINED3DERR_INVALIDCALL;
1529 pMode->Width = 800;
1530 pMode->Height = 600;
1531 pMode->RefreshRate = 60;
1532 pMode->Format = (Format == WINED3DFMT_UNKNOWN) ? WINED3DFMT_X8R8G8B8 : Format;
1533 } else {
1534 FIXME_(d3d_caps)("Adapter not primary display\n");
1537 return WINED3D_OK;
1540 static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, WINED3DDISPLAYMODE* pMode) {
1541 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1542 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
1544 if (NULL == pMode ||
1545 Adapter >= IWineD3D_GetAdapterCount(iface)) {
1546 return WINED3DERR_INVALIDCALL;
1549 if (Adapter == 0) { /* Display */
1550 int bpp = 0;
1551 DEVMODEW DevModeW;
1553 ZeroMemory(&DevModeW, sizeof(DevModeW));
1554 DevModeW.dmSize = sizeof(DevModeW);
1556 EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &DevModeW, 0);
1557 pMode->Width = DevModeW.dmPelsWidth;
1558 pMode->Height = DevModeW.dmPelsHeight;
1559 bpp = DevModeW.dmBitsPerPel;
1560 pMode->RefreshRate = WINED3DADAPTER_DEFAULT;
1561 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
1563 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
1566 pMode->Format = pixelformat_for_depth(bpp);
1567 } else {
1568 FIXME_(d3d_caps)("Adapter not primary display\n");
1571 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
1572 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
1573 return WINED3D_OK;
1576 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
1577 and fields being inserted in the middle, a new structure is used in place */
1578 static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
1579 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
1580 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1582 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %x, pId=%p)\n", This, Adapter, Flags, pIdentifier);
1584 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1585 return WINED3DERR_INVALIDCALL;
1588 /* Return the information requested */
1589 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
1590 strcpy(pIdentifier->Driver, Adapters[Adapter].driver);
1591 strcpy(pIdentifier->Description, Adapters[Adapter].description);
1593 /* Note dx8 doesn't supply a DeviceName */
1594 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
1595 pIdentifier->DriverVersion->u.HighPart = Adapters[Adapter].gl_info.driver_version_hipart;
1596 pIdentifier->DriverVersion->u.LowPart = Adapters[Adapter].gl_info.driver_version;
1597 *(pIdentifier->VendorId) = Adapters[Adapter].gl_info.gl_vendor;
1598 *(pIdentifier->DeviceId) = Adapters[Adapter].gl_info.gl_card;
1599 *(pIdentifier->SubSysId) = 0;
1600 *(pIdentifier->Revision) = 0;
1601 *pIdentifier->DeviceIdentifier = IID_D3DDEVICE_D3DUID;
1603 if (Flags & WINED3DENUM_NO_WHQL_LEVEL) {
1604 *(pIdentifier->WHQLLevel) = 0;
1605 } else {
1606 *(pIdentifier->WHQLLevel) = 1;
1609 return WINED3D_OK;
1612 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const WineD3D_PixelFormat *cfg, WINED3DFORMAT Format) {
1613 short redSize, greenSize, blueSize, alphaSize, colorBits;
1615 if(!cfg)
1616 return FALSE;
1618 if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */
1619 if(!getColorBits(Format, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits)) {
1620 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(Format));
1621 return FALSE;
1624 if(cfg->redSize < redSize)
1625 return FALSE;
1627 if(cfg->greenSize < greenSize)
1628 return FALSE;
1630 if(cfg->blueSize < blueSize)
1631 return FALSE;
1633 if(cfg->alphaSize < alphaSize)
1634 return FALSE;
1636 return TRUE;
1637 } else if(cfg->iPixelType == WGL_TYPE_RGBA_FLOAT_ARB) { /* Float RGBA formats; TODO: WGL_NV_float_buffer */
1638 if(Format == WINED3DFMT_R16F)
1639 return (cfg->redSize == 16 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1640 if(Format == WINED3DFMT_G16R16F)
1641 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1642 if(Format == WINED3DFMT_A16B16G16R16F)
1643 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 16 && cfg->alphaSize == 16);
1644 if(Format == WINED3DFMT_R32F)
1645 return (cfg->redSize == 32 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1646 if(Format == WINED3DFMT_G32R32F)
1647 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 0 && cfg->alphaSize == 0);
1648 if(Format == WINED3DFMT_A32B32G32R32F)
1649 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 32 && cfg->alphaSize == 32);
1650 } else {
1651 /* Probably a color index mode */
1652 return FALSE;
1655 return FALSE;
1658 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const WineD3D_PixelFormat *cfg, WINED3DFORMAT Format) {
1659 short depthSize, stencilSize;
1660 BOOL lockable = FALSE;
1662 if(!cfg)
1663 return FALSE;
1665 if(!getDepthStencilBits(Format, &depthSize, &stencilSize)) {
1666 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(Format));
1667 return FALSE;
1670 if((Format == WINED3DFMT_D16_LOCKABLE) || (Format == WINED3DFMT_D32F_LOCKABLE))
1671 lockable = TRUE;
1673 /* On some modern cards like the Geforce8/9 GLX doesn't offer some dephthstencil formats which D3D9 reports.
1674 * We can safely report 'compatible' formats (e.g. D24 can be used for D16) as long as we aren't dealing with
1675 * a lockable format. This also helps D3D <= 7 as they expect D16 which isn't offered without this on Geforce8 cards. */
1676 if(!(cfg->depthSize == depthSize || (!lockable && cfg->depthSize > depthSize)))
1677 return FALSE;
1679 if(cfg->stencilSize != stencilSize)
1680 return FALSE;
1682 return TRUE;
1685 static HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1686 WINED3DFORMAT AdapterFormat,
1687 WINED3DFORMAT RenderTargetFormat,
1688 WINED3DFORMAT DepthStencilFormat) {
1689 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1690 int nCfgs;
1691 WineD3D_PixelFormat *cfgs;
1692 int it;
1694 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
1695 This, Adapter,
1696 DeviceType, debug_d3ddevicetype(DeviceType),
1697 AdapterFormat, debug_d3dformat(AdapterFormat),
1698 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
1699 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
1701 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1702 TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning WINED3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
1703 return WINED3DERR_INVALIDCALL;
1706 cfgs = Adapters[Adapter].cfgs;
1707 nCfgs = Adapters[Adapter].nCfgs;
1708 for (it = 0; it < nCfgs; ++it) {
1709 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], RenderTargetFormat)) {
1710 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&cfgs[it], DepthStencilFormat)) {
1711 TRACE_(d3d_caps)("(%p) : Formats matched\n", This);
1712 return WINED3D_OK;
1716 WARN_(d3d_caps)("unsupported format pair: %s and %s\n", debug_d3dformat(RenderTargetFormat), debug_d3dformat(DepthStencilFormat));
1718 return WINED3DERR_NOTAVAILABLE;
1721 static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1722 WINED3DFORMAT SurfaceFormat,
1723 BOOL Windowed, WINED3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
1725 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1726 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
1727 This,
1728 Adapter,
1729 DeviceType, debug_d3ddevicetype(DeviceType),
1730 SurfaceFormat, debug_d3dformat(SurfaceFormat),
1731 Windowed,
1732 MultiSampleType,
1733 pQualityLevels);
1735 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1736 return WINED3DERR_INVALIDCALL;
1739 /* TODO: Store in Adapter structure */
1740 if (pQualityLevels != NULL) {
1741 static int s_single_shot = 0;
1742 if (!s_single_shot) {
1743 FIXME("Quality levels unsupported at present\n");
1744 s_single_shot = 1;
1746 *pQualityLevels = 1; /* Guess at a value! */
1749 if (WINED3DMULTISAMPLE_NONE == MultiSampleType) return WINED3D_OK;
1750 return WINED3DERR_NOTAVAILABLE;
1753 static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
1754 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
1756 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1757 HRESULT hr = WINED3DERR_NOTAVAILABLE;
1758 UINT nmodes;
1760 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
1761 This,
1762 Adapter,
1763 DeviceType, debug_d3ddevicetype(DeviceType),
1764 DisplayFormat, debug_d3dformat(DisplayFormat),
1765 BackBufferFormat, debug_d3dformat(BackBufferFormat),
1766 Windowed);
1768 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1769 WARN_(d3d_caps)("Adapter >= IWineD3D_GetAdapterCount(iface), returning WINED3DERR_INVALIDCALL\n");
1770 return WINED3DERR_INVALIDCALL;
1773 /* The task of this function is to check whether a certain display / backbuffer format
1774 * combination is available on the given adapter. In fullscreen mode microsoft specified
1775 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
1776 * and display format should match exactly.
1777 * In windowed mode format conversion can occur and this depends on the driver. When format
1778 * conversion is done, this function should nevertheless fail and applications need to use
1779 * CheckDeviceFormatConversion.
1780 * At the moment we assume that fullscreen and windowed have the same capabilities */
1782 /* There are only 4 display formats */
1783 if(!((DisplayFormat == WINED3DFMT_R5G6B5) ||
1784 (DisplayFormat == WINED3DFMT_X1R5G5B5) ||
1785 (DisplayFormat == WINED3DFMT_X8R8G8B8) ||
1786 (DisplayFormat == WINED3DFMT_A2R10G10B10)))
1788 TRACE_(d3d_caps)("Format %s unsupported as display format\n", debug_d3dformat(DisplayFormat));
1789 return WINED3DERR_NOTAVAILABLE;
1792 /* If the requested DisplayFormat is not available, don't continue */
1793 nmodes = IWineD3DImpl_GetAdapterModeCount(iface, Adapter, DisplayFormat);
1794 if(!nmodes) {
1795 TRACE_(d3d_caps)("No available modes for display format %s\n", debug_d3dformat(DisplayFormat));
1796 return WINED3DERR_NOTAVAILABLE;
1799 /* Windowed mode allows you to specify WINED3DFMT_UNKNOWN for the backbufferformat, it means 'reuse' the display format for the backbuffer */
1800 if(!Windowed && BackBufferFormat == WINED3DFMT_UNKNOWN) {
1801 TRACE_(d3d_caps)("BackBufferFormat WINED3FMT_UNKNOWN not available in Windowed mode\n");
1802 return WINED3DERR_NOTAVAILABLE;
1805 /* In FULLSCREEN mode R5G6B5 can only be mixed with backbuffer format R5G6B5 */
1806 if( (DisplayFormat == WINED3DFMT_R5G6B5) && (BackBufferFormat != WINED3DFMT_R5G6B5) ) {
1807 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1808 return WINED3DERR_NOTAVAILABLE;
1811 /* In FULLSCREEN mode X1R5G5B5 can only be mixed with backbuffer format *1R5G5B5 */
1812 if( (DisplayFormat == WINED3DFMT_X1R5G5B5) && !((BackBufferFormat == WINED3DFMT_X1R5G5B5) || (BackBufferFormat == WINED3DFMT_A1R5G5B5)) ) {
1813 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1814 return WINED3DERR_NOTAVAILABLE;
1817 /* In FULLSCREEN mode X8R8G8B8 can only be mixed with backbuffer format *8R8G8B8 */
1818 if( (DisplayFormat == WINED3DFMT_X8R8G8B8) && !((BackBufferFormat == WINED3DFMT_X8R8G8B8) || (BackBufferFormat == WINED3DFMT_A8R8G8B8)) ) {
1819 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1820 return WINED3DERR_NOTAVAILABLE;
1823 /* A2R10G10B10 is only allowed in fullscreen mode and it can only be mixed with backbuffer format A2R10G10B10 */
1824 if( (DisplayFormat == WINED3DFMT_A2R10G10B10) && ((BackBufferFormat != WINED3DFMT_A2R10G10B10) || Windowed)) {
1825 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1826 return WINED3DERR_NOTAVAILABLE;
1829 /* Use CheckDeviceFormat to see if the BackBufferFormat is usable with the given DisplayFormat */
1830 hr = IWineD3DImpl_CheckDeviceFormat(iface, Adapter, DeviceType, DisplayFormat, WINED3DUSAGE_RENDERTARGET, WINED3DRTYPE_SURFACE, BackBufferFormat);
1831 if(FAILED(hr))
1832 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
1834 return hr;
1838 #define GLINFO_LOCATION Adapters[Adapter].gl_info
1839 /* Check if we support bumpmapping for a format */
1840 static BOOL CheckBumpMapCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
1842 if(GL_SUPPORT(NV_REGISTER_COMBINERS) && GL_SUPPORT(NV_TEXTURE_SHADER2)) {
1843 switch (CheckFormat) {
1844 case WINED3DFMT_V8U8:
1845 TRACE_(d3d_caps)("[OK]\n");
1846 return TRUE;
1847 /* TODO: Other bump map formats */
1848 default:
1849 TRACE_(d3d_caps)("[FAILED]\n");
1850 return FALSE;
1853 if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
1854 switch (CheckFormat) {
1855 case WINED3DFMT_V8U8:
1856 TRACE_(d3d_caps)("[OK]\n");
1857 return TRUE;
1858 default:
1859 TRACE_(d3d_caps)("[FAILED]\n");
1860 return FALSE;
1863 TRACE_(d3d_caps)("[FAILED]\n");
1864 return FALSE;
1867 /* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
1868 static BOOL CheckDepthStencilCapability(UINT Adapter, WINED3DFORMAT DisplayFormat,
1869 WINED3DFORMAT DepthStencilFormat)
1871 int it=0;
1872 WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
1874 /* Only allow depth/stencil formats */
1875 switch (DepthStencilFormat) {
1876 case WINED3DFMT_D16_LOCKABLE:
1877 case WINED3DFMT_D16:
1878 case WINED3DFMT_D15S1:
1879 case WINED3DFMT_D24X8:
1880 case WINED3DFMT_D24X4S4:
1881 case WINED3DFMT_D24S8:
1882 case WINED3DFMT_D24FS8:
1883 case WINED3DFMT_D32:
1884 case WINED3DFMT_D32F_LOCKABLE:
1885 break;
1887 default:
1888 return FALSE;
1891 /* Walk through all WGL pixel formats to find a match */
1892 cfgs = Adapters[Adapter].cfgs;
1893 for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
1894 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], DisplayFormat)) {
1895 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&cfgs[it], DepthStencilFormat)) {
1896 return TRUE;
1901 return FALSE;
1904 static BOOL CheckFilterCapability(WINED3DFORMAT CheckFormat)
1906 switch (CheckFormat) {
1907 /* Filtering not supported */
1908 case WINED3DFMT_R32F:
1909 case WINED3DFMT_A32B32G32R32F:
1910 TRACE_(d3d_caps)("[FAILED]\n");
1911 return FALSE;
1912 default:
1913 break;
1916 return TRUE;
1919 /* Check the render target capabilities of a format */
1920 static BOOL CheckRenderTargetCapability(WINED3DFORMAT AdapterFormat, WINED3DFORMAT CheckFormat)
1922 UINT Adapter = 0;
1924 /* Filter out non-RT formats */
1925 switch(CheckFormat)
1927 /* Don't offer 8bit, windows doesn't either although we could emulate it */
1928 case WINED3DFMT_A8P8:
1929 case WINED3DFMT_P8:
1931 /* No DXTC render targets */
1932 case WINED3DFMT_DXT1:
1933 case WINED3DFMT_DXT2:
1934 case WINED3DFMT_DXT3:
1935 case WINED3DFMT_DXT4:
1936 case WINED3DFMT_DXT5:
1937 return FALSE;
1938 default:
1939 break;
1942 if(wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) {
1943 WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
1944 int it;
1945 short AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
1946 short CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
1948 getColorBits(AdapterFormat, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
1949 getColorBits(CheckFormat, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
1951 /* In backbuffer mode the front and backbuffer share the same WGL pixelformat.
1952 * The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */
1953 if(!((AdapterRed == CheckRed) && (AdapterGreen == CheckGreen) && (AdapterBlue == CheckBlue))) {
1954 TRACE_(d3d_caps)("[FAILED]\n");
1955 return FALSE;
1958 /* Check if there is a WGL pixel format matching the requirements, the format should also be window
1959 * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
1960 for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
1961 if (cfgs[it].windowDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], CheckFormat)) {
1962 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n", cfgs[it].iPixelFormat, debug_d3dformat(CheckFormat));
1963 return TRUE;
1966 } else if(wined3d_settings.offscreen_rendering_mode == ORM_PBUFFER) {
1967 /* We can propably use this function in FBO mode too on some drivers to get some basic indication of the capabilities. */
1968 WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
1969 int it;
1971 /* Check if there is a WGL pixel format matching the requirements, the pixel format should also be usable with pbuffers */
1972 for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
1973 if (cfgs[it].pbufferDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], CheckFormat)) {
1974 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n", cfgs[it].iPixelFormat, debug_d3dformat(CheckFormat));
1975 return TRUE;
1978 } else if(wined3d_settings.offscreen_rendering_mode == ORM_FBO){
1979 /* For now return TRUE for FBOs until we have some proper checks.
1980 * Note that this function will only be called when the format is around for texturing. */
1981 return TRUE;
1983 return FALSE;
1986 static BOOL CheckSrgbReadCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
1988 /* Check for supported sRGB formats (Texture loading and framebuffer) */
1989 if(!GL_SUPPORT(EXT_TEXTURE_SRGB)) {
1990 TRACE_(d3d_caps)("[FAILED] GL_EXT_texture_sRGB not supported\n");
1991 return FALSE;
1994 switch (CheckFormat) {
1995 case WINED3DFMT_A8R8G8B8:
1996 case WINED3DFMT_X8R8G8B8:
1997 case WINED3DFMT_A4R4G4B4:
1998 case WINED3DFMT_L8:
1999 case WINED3DFMT_A8L8:
2000 case WINED3DFMT_DXT1:
2001 case WINED3DFMT_DXT2:
2002 case WINED3DFMT_DXT3:
2003 case WINED3DFMT_DXT4:
2004 case WINED3DFMT_DXT5:
2005 TRACE_(d3d_caps)("[OK]\n");
2006 return TRUE;
2008 default:
2009 TRACE_(d3d_caps)("[FAILED] Gamma texture format %s not supported.\n", debug_d3dformat(CheckFormat));
2010 return FALSE;
2012 return FALSE;
2015 static BOOL CheckSrgbWriteCapability(UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT CheckFormat)
2017 /* Only offer SRGB writing on X8R8G8B8/A8R8G8B8 when we use ARB or GLSL shaders as we are
2018 * doing the color fixup in shaders.
2019 * Note Windows drivers (at least on the Geforce 8800) also offer this on R5G6B5. */
2020 if((CheckFormat == WINED3DFMT_X8R8G8B8) || (CheckFormat == WINED3DFMT_A8R8G8B8)) {
2021 int vs_selected_mode;
2022 int ps_selected_mode;
2023 select_shader_mode(&GLINFO_LOCATION, DeviceType, &ps_selected_mode, &vs_selected_mode);
2025 if((ps_selected_mode == SHADER_ARB) || (ps_selected_mode == SHADER_GLSL)) {
2026 TRACE_(d3d_caps)("[OK]\n");
2027 return TRUE;
2031 TRACE_(d3d_caps)("[FAILED] - no SRGB writing support on format=%s\n", debug_d3dformat(CheckFormat));
2032 return FALSE;
2035 /* Check if a texture format is supported on the given adapter */
2036 static BOOL CheckTextureCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2038 switch (CheckFormat) {
2040 /*****
2041 * supported: RGB(A) formats
2043 case WINED3DFMT_R8G8B8: /* Enable for dx7, blacklisted for 8 and 9 above */
2044 case WINED3DFMT_A8R8G8B8:
2045 case WINED3DFMT_X8R8G8B8:
2046 case WINED3DFMT_R5G6B5:
2047 case WINED3DFMT_X1R5G5B5:
2048 case WINED3DFMT_A1R5G5B5:
2049 case WINED3DFMT_A4R4G4B4:
2050 case WINED3DFMT_R3G3B2:
2051 case WINED3DFMT_A8:
2052 case WINED3DFMT_X4R4G4B4:
2053 case WINED3DFMT_A8B8G8R8:
2054 case WINED3DFMT_X8B8G8R8:
2055 case WINED3DFMT_A2R10G10B10:
2056 case WINED3DFMT_A2B10G10R10:
2057 case WINED3DFMT_G16R16:
2058 TRACE_(d3d_caps)("[OK]\n");
2059 return TRUE;
2061 /*****
2062 * supported: Palettized
2064 case WINED3DFMT_P8:
2065 TRACE_(d3d_caps)("[OK]\n");
2066 return TRUE;
2067 /* No Windows driver offers A8P8, so don't offer it either */
2068 case WINED3DFMT_A8P8:
2069 return FALSE;
2071 /*****
2072 * Supported: (Alpha)-Luminance
2074 case WINED3DFMT_L8:
2075 case WINED3DFMT_A8L8:
2076 case WINED3DFMT_A4L4:
2077 case WINED3DFMT_L16:
2078 TRACE_(d3d_caps)("[OK]\n");
2079 return TRUE;
2081 /* Depth/stencil is handled using checkDepthStencilCapability, return FALSE here */
2082 case WINED3DFMT_D16_LOCKABLE:
2083 case WINED3DFMT_D16:
2084 case WINED3DFMT_D15S1:
2085 case WINED3DFMT_D24X8:
2086 case WINED3DFMT_D24X4S4:
2087 case WINED3DFMT_D24S8:
2088 case WINED3DFMT_D24FS8:
2089 case WINED3DFMT_D32:
2090 case WINED3DFMT_D32F_LOCKABLE:
2091 return FALSE;
2093 /*****
2094 * Not supported everywhere(depends on GL_ATI_envmap_bumpmap or
2095 * GL_NV_texture_shader), but advertized to make apps happy.
2096 * Enable some because games often fail when they are not available
2097 * and are still playable even without bump mapping
2099 case WINED3DFMT_V8U8:
2100 if(GL_SUPPORT(NV_TEXTURE_SHADER) || GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
2101 return TRUE;
2103 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2104 return FALSE;
2106 case WINED3DFMT_X8L8V8U8:
2107 case WINED3DFMT_L6V5U5:
2108 WARN_(d3d_caps)("[FAILED]\n");
2109 return FALSE;
2111 case WINED3DFMT_Q8W8V8U8:
2112 case WINED3DFMT_V16U16:
2113 if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
2114 WARN_(d3d_caps)("[Not supported, but pretended to do]\n");
2115 return TRUE;
2117 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2118 return FALSE;
2120 /* Those are not advertized by the nvidia windows driver, and not
2121 * supported natively by GL_NV_texture_shader or GL_ATI_envmap_bumpmap.
2122 * WINED3DFMT_A2W10V10U10 could be loaded into shaders using the unsigned
2123 * ARGB format if needed
2125 case WINED3DFMT_W11V11U10:
2126 case WINED3DFMT_A2W10V10U10:
2127 WARN_(d3d_caps)("[FAILED]\n");
2128 return FALSE;
2130 case WINED3DFMT_DXT1:
2131 case WINED3DFMT_DXT2:
2132 case WINED3DFMT_DXT3:
2133 case WINED3DFMT_DXT4:
2134 case WINED3DFMT_DXT5:
2135 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
2136 TRACE_(d3d_caps)("[OK]\n");
2137 return TRUE;
2139 TRACE_(d3d_caps)("[FAILED]\n");
2140 return FALSE;
2143 /*****
2144 * Odd formats - not supported
2146 case WINED3DFMT_VERTEXDATA:
2147 case WINED3DFMT_INDEX16:
2148 case WINED3DFMT_INDEX32:
2149 case WINED3DFMT_Q16W16V16U16:
2150 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2151 return FALSE;
2153 /*****
2154 * WINED3DFMT_CxV8U8: Not supported right now
2156 case WINED3DFMT_CxV8U8:
2157 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2158 return FALSE;
2160 /* YUV formats, not supported for now */
2161 case WINED3DFMT_UYVY:
2162 case WINED3DFMT_YUY2:
2163 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2164 return FALSE;
2166 /* Not supported */
2167 case WINED3DFMT_A16B16G16R16:
2168 case WINED3DFMT_A8R3G3B2:
2169 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2170 return FALSE;
2172 /* Floating point formats */
2173 case WINED3DFMT_R16F:
2174 case WINED3DFMT_A16B16G16R16F:
2175 if(GL_SUPPORT(ARB_HALF_FLOAT_PIXEL)) {
2176 TRACE_(d3d_caps)("[OK]\n");
2177 return TRUE;
2179 TRACE_(d3d_caps)("[FAILED]\n");
2180 return FALSE;
2182 case WINED3DFMT_R32F:
2183 case WINED3DFMT_A32B32G32R32F:
2184 if (GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2185 TRACE_(d3d_caps)("[OK]\n");
2186 return TRUE;
2188 TRACE_(d3d_caps)("[FAILED]\n");
2189 return FALSE;
2191 case WINED3DFMT_G16R16F:
2192 case WINED3DFMT_G32R32F:
2193 TRACE_(d3d_caps)("[FAILED]\n");
2194 return FALSE;
2196 /* ATI instancing hack: Although ATI cards do not support Shader Model 3.0, they support
2197 * instancing. To query if the card supports instancing CheckDeviceFormat with the special format
2198 * MAKEFOURCC('I','N','S','T') is used. Should a (broken) app check for this provide a proper return value.
2199 * We can do instancing with all shader versions, but we need vertex shaders.
2201 * Additionally applications have to set the D3DRS_POINTSIZE render state to MAKEFOURCC('I','N','S','T') once
2202 * to enable instancing. WineD3D doesn't need that and just ignores it.
2204 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows.
2206 case WINEMAKEFOURCC('I','N','S','T'):
2207 TRACE("ATI Instancing check hack\n");
2208 if(GL_SUPPORT(ARB_VERTEX_PROGRAM) || GL_SUPPORT(ARB_VERTEX_SHADER)) {
2209 TRACE_(d3d_caps)("[OK]\n");
2210 return TRUE;
2212 TRACE_(d3d_caps)("[FAILED]\n");
2213 return FALSE;
2215 /* Some weird FOURCC formats */
2216 case WINED3DFMT_R8G8_B8G8:
2217 case WINED3DFMT_G8R8_G8B8:
2218 case WINED3DFMT_MULTI2_ARGB8:
2219 TRACE_(d3d_caps)("[FAILED]\n");
2220 return FALSE;
2222 case WINED3DFMT_UNKNOWN:
2223 return FALSE;
2225 default:
2226 ERR("Unhandled format=%s\n", debug_d3dformat(CheckFormat));
2227 break;
2229 return FALSE;
2232 static BOOL CheckVertexTextureCapability(UINT Adapter, WINED3DFORMAT CheckFormat)
2234 if (!GL_LIMITS(vertex_samplers)) {
2235 TRACE_(d3d_caps)("[FAILED]\n");
2236 return FALSE;
2239 switch (CheckFormat) {
2240 case WINED3DFMT_A32B32G32R32F:
2241 if (!GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2242 TRACE_(d3d_caps)("[FAILED]\n");
2243 return FALSE;
2245 TRACE_(d3d_caps)("[OK]\n");
2246 return TRUE;
2248 default:
2249 TRACE_(d3d_caps)("[FAILED]\n");
2250 return FALSE;
2252 return FALSE;
2255 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2256 WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat) {
2257 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2258 DWORD UsageCaps = 0;
2260 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%u,%s,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s))\n",
2261 This,
2262 Adapter,
2263 DeviceType, debug_d3ddevicetype(DeviceType),
2264 AdapterFormat, debug_d3dformat(AdapterFormat),
2265 Usage, debug_d3dusage(Usage), debug_d3dusagequery(Usage),
2266 RType, debug_d3dresourcetype(RType),
2267 CheckFormat, debug_d3dformat(CheckFormat));
2269 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2270 return WINED3DERR_INVALIDCALL;
2273 if(RType == WINED3DRTYPE_CUBETEXTURE) {
2274 /* Cubetexture allows:
2275 * - D3DUSAGE_AUTOGENMIPMAP
2276 * - D3DUSAGE_DEPTHSTENCIL
2277 * - D3DUSAGE_DYNAMIC
2278 * - D3DUSAGE_NONSECURE (d3d9ex)
2279 * - D3DUSAGE_RENDERTARGET
2280 * - D3DUSAGE_SOFTWAREPROCESSING
2282 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2283 /* Check if the texture format is around */
2284 if(CheckTextureCapability(Adapter, CheckFormat)) {
2285 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
2286 /* Check for automatic mipmap generation support */
2287 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2288 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
2289 } else {
2290 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUOTGEN instead of D3D_OK */
2291 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
2295 /* Always report dynamic locking */
2296 if(Usage & WINED3DUSAGE_DYNAMIC)
2297 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2299 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2300 if(CheckRenderTargetCapability(AdapterFormat, CheckFormat)) {
2301 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2302 } else {
2303 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2304 return WINED3DERR_NOTAVAILABLE;
2308 /* Always report software processing */
2309 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2310 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2312 /* Check QUERY_FILTER support */
2313 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2314 if(CheckFilterCapability(CheckFormat)) {
2315 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2316 } else {
2317 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2318 return WINED3DERR_NOTAVAILABLE;
2322 /* Check QUERY_SRGBREAD support */
2323 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2324 if(CheckSrgbReadCapability(Adapter, CheckFormat)) {
2325 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2326 } else {
2327 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2328 return WINED3DERR_NOTAVAILABLE;
2332 /* Check QUERY_SRGBWRITE support */
2333 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2334 if(CheckSrgbWriteCapability(Adapter, DeviceType, CheckFormat)) {
2335 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2336 } else {
2337 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2338 return WINED3DERR_NOTAVAILABLE;
2342 /* Check QUERY_VERTEXTEXTURE support */
2343 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2344 if(CheckVertexTextureCapability(Adapter, CheckFormat)) {
2345 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2346 } else {
2347 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2348 return WINED3DERR_NOTAVAILABLE;
2351 } else {
2352 TRACE_(d3d_caps)("[FAILED] - Cube texture format not supported\n");
2353 return WINED3DERR_NOTAVAILABLE;
2355 } else {
2356 TRACE_(d3d_caps)("[FAILED] - No cube texture support\n");
2357 return WINED3DERR_NOTAVAILABLE;
2359 } else if(RType == WINED3DRTYPE_SURFACE) {
2360 /* Surface allows:
2361 * - D3DUSAGE_DEPTHSTENCIL
2362 * - D3DUSAGE_NONSECURE (d3d9ex)
2363 * - D3DUSAGE_RENDERTARGET
2366 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
2367 if(CheckDepthStencilCapability(Adapter, AdapterFormat, CheckFormat)) {
2368 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
2369 } else {
2370 TRACE_(d3d_caps)("[FAILED] - No depthstencil support\n");
2371 return WINED3DERR_NOTAVAILABLE;
2375 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2376 if(CheckRenderTargetCapability(AdapterFormat, CheckFormat)) {
2377 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2378 } else {
2379 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2380 return WINED3DERR_NOTAVAILABLE;
2383 } else if(RType == WINED3DRTYPE_TEXTURE) {
2384 /* Texture allows:
2385 * - D3DUSAGE_AUTOGENMIPMAP
2386 * - D3DUSAGE_DEPTHSTENCIL
2387 * - D3DUSAGE_DMAP
2388 * - D3DUSAGE_DYNAMIC
2389 * - D3DUSAGE_NONSECURE (d3d9ex)
2390 * - D3DUSAGE_RENDERTARGET
2391 * - D3DUSAGE_SOFTWAREPROCESSING
2392 * - D3DUSAGE_TEXTAPI (d3d9ex)
2395 /* Check if the texture format is around */
2396 if(CheckTextureCapability(Adapter, CheckFormat)) {
2397 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
2398 /* Check for automatic mipmap generation support */
2399 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2400 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
2401 } else {
2402 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUOTGEN instead of D3D_OK */
2403 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
2407 /* Always report dynamic locking */
2408 if(Usage & WINED3DUSAGE_DYNAMIC)
2409 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2411 if(Usage & WINED3DUSAGE_RENDERTARGET) {
2412 if(CheckRenderTargetCapability(AdapterFormat, CheckFormat)) {
2413 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
2414 } else {
2415 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
2416 return WINED3DERR_NOTAVAILABLE;
2420 /* Always report software processing */
2421 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2422 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2424 /* Check QUERY_FILTER support */
2425 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2426 if(CheckFilterCapability(CheckFormat)) {
2427 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2428 } else {
2429 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2430 return WINED3DERR_NOTAVAILABLE;
2434 /* Check QUERY_LEGACYBUMPMAP support */
2435 if(Usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP) {
2436 if(CheckBumpMapCapability(Adapter, CheckFormat)) {
2437 UsageCaps |= WINED3DUSAGE_QUERY_LEGACYBUMPMAP;
2438 } else {
2439 TRACE_(d3d_caps)("[FAILED] - No legacy bumpmap support\n");
2440 return WINED3DERR_NOTAVAILABLE;
2444 /* Check QUERY_SRGBREAD support */
2445 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2446 if(CheckSrgbReadCapability(Adapter, CheckFormat)) {
2447 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2448 } else {
2449 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2450 return WINED3DERR_NOTAVAILABLE;
2454 /* Check QUERY_SRGBWRITE support */
2455 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2456 if(CheckSrgbWriteCapability(Adapter, DeviceType, CheckFormat)) {
2457 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2458 } else {
2459 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2460 return WINED3DERR_NOTAVAILABLE;
2464 /* Check QUERY_VERTEXTEXTURE support */
2465 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2466 if(CheckVertexTextureCapability(Adapter, CheckFormat)) {
2467 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2468 } else {
2469 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2470 return WINED3DERR_NOTAVAILABLE;
2473 } else if(CheckDepthStencilCapability(Adapter, AdapterFormat, CheckFormat)) {
2474 if(Usage & WINED3DUSAGE_DEPTHSTENCIL)
2475 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
2476 } else {
2477 TRACE_(d3d_caps)("[FAILED] - Texture format not supported\n");
2478 return WINED3DERR_NOTAVAILABLE;
2480 } else if((RType == WINED3DRTYPE_VOLUME) || (RType == WINED3DRTYPE_VOLUMETEXTURE)) {
2481 /* Volume is to VolumeTexture what Surface is to Texture but its usage caps are not documented.
2482 * Most driver seem to offer (nearly) the same on Volume and VolumeTexture, so do that too.
2484 * Volumetexture allows:
2485 * - D3DUSAGE_DYNAMIC
2486 * - D3DUSAGE_NONSECURE (d3d9ex)
2487 * - D3DUSAGE_SOFTWAREPROCESSING
2490 /* Check volume texture and volume usage caps */
2491 if(GL_SUPPORT(EXT_TEXTURE3D)) {
2492 if(CheckTextureCapability(Adapter, CheckFormat) == FALSE) {
2493 TRACE_(d3d_caps)("[FAILED] - Format not supported\n");
2494 return WINED3DERR_NOTAVAILABLE;
2497 /* Always report dynamic locking */
2498 if(Usage & WINED3DUSAGE_DYNAMIC)
2499 UsageCaps |= WINED3DUSAGE_DYNAMIC;
2501 /* Always report software processing */
2502 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
2503 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
2505 /* Check QUERY_FILTER support */
2506 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
2507 if(CheckFilterCapability(CheckFormat)) {
2508 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
2509 } else {
2510 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
2511 return WINED3DERR_NOTAVAILABLE;
2515 /* Check QUERY_SRGBREAD support */
2516 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
2517 if(CheckSrgbReadCapability(Adapter, CheckFormat)) {
2518 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
2519 } else {
2520 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
2521 return WINED3DERR_NOTAVAILABLE;
2525 /* Check QUERY_SRGBWRITE support */
2526 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
2527 if(CheckSrgbWriteCapability(Adapter, DeviceType, CheckFormat)) {
2528 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
2529 } else {
2530 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
2531 return WINED3DERR_NOTAVAILABLE;
2535 /* Check QUERY_VERTEXTEXTURE support */
2536 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
2537 if(CheckVertexTextureCapability(Adapter, CheckFormat)) {
2538 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
2539 } else {
2540 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
2541 return WINED3DERR_NOTAVAILABLE;
2544 } else {
2545 TRACE_(d3d_caps)("[FAILED] - No volume texture support\n");
2546 return WINED3DERR_NOTAVAILABLE;
2549 /* Filter formats that need conversion; For one part, this conversion is unimplemented,
2550 * and volume textures are huge, so it would be a big performance hit. Unless we hit an
2551 * app needing one of those formats, don't advertize them to avoid leading apps into
2552 * temptation. The windows drivers don't support most of those formats on volumes anyway,
2553 * except of R32F.
2555 switch(CheckFormat) {
2556 case WINED3DFMT_P8:
2557 case WINED3DFMT_A4L4:
2558 case WINED3DFMT_R32F:
2559 case WINED3DFMT_R16F:
2560 case WINED3DFMT_X8L8V8U8:
2561 case WINED3DFMT_L6V5U5:
2562 case WINED3DFMT_G16R16:
2563 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2564 return WINED3DERR_NOTAVAILABLE;
2566 case WINED3DFMT_Q8W8V8U8:
2567 case WINED3DFMT_V16U16:
2568 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
2569 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2570 return WINED3DERR_NOTAVAILABLE;
2572 break;
2574 case WINED3DFMT_V8U8:
2575 if(!GL_SUPPORT(NV_TEXTURE_SHADER) || !GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
2576 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
2577 return WINED3DERR_NOTAVAILABLE;
2579 break;
2581 case WINED3DFMT_DXT1:
2582 case WINED3DFMT_DXT2:
2583 case WINED3DFMT_DXT3:
2584 case WINED3DFMT_DXT4:
2585 case WINED3DFMT_DXT5:
2586 /* The GL_EXT_texture_compression_s3tc spec requires that loading an s3tc
2587 * compressed texture results in an error. While the D3D refrast does
2588 * support s3tc volumes, at least the nvidia windows driver does not, so
2589 * we're free not to support this format.
2591 TRACE_(d3d_caps)("[FAILED] - DXTn does not support 3D textures\n");
2592 return WINED3DERR_NOTAVAILABLE;
2594 default:
2595 /* Do nothing, continue with checking the format below */
2596 break;
2598 } else if((RType == WINED3DRTYPE_INDEXBUFFER) || (RType == WINED3DRTYPE_VERTEXBUFFER)){
2599 /* For instance vertexbuffer/indexbuffer aren't supported yet because no Windows drivers seem to offer it */
2600 TRACE_(d3d_caps)("Unhandled resource type D3DRTYPE_INDEXBUFFER / D3DRTYPE_VERTEXBUFFER\n");
2601 return WINED3DERR_NOTAVAILABLE;
2604 /* This format is nothing special and it is supported perfectly.
2605 * However, ati and nvidia driver on windows do not mark this format as
2606 * supported (tested with the dxCapsViewer) and pretending to
2607 * support this format uncovers a bug in Battlefield 1942 (fonts are missing)
2608 * So do the same as Windows drivers and pretend not to support it on dx8 and 9
2609 * Enable it on dx7. It will need additional checking on dx10 when we support it.
2611 if(This->dxVersion > 7 && CheckFormat == WINED3DFMT_R8G8B8) {
2612 TRACE_(d3d_caps)("[FAILED]\n");
2613 return WINED3DERR_NOTAVAILABLE;
2616 /* When the UsageCaps exactly matches Usage return WINED3D_OK except for the situation in which
2617 * WINED3DUSAGE_AUTOGENMIPMAP isn't around, then WINED3DOK_NOAUTOGEN is returned if all the other
2618 * usage flags match. */
2619 if(UsageCaps == Usage) {
2620 return WINED3D_OK;
2621 } else if((UsageCaps == (Usage & ~WINED3DUSAGE_AUTOGENMIPMAP)) && (Usage & WINED3DUSAGE_AUTOGENMIPMAP)){
2622 return WINED3DOK_NOAUTOGEN;
2623 } else {
2624 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);
2625 return WINED3DERR_NOTAVAILABLE;
2629 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2630 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
2631 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2633 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))\n",
2634 This,
2635 Adapter,
2636 DeviceType, debug_d3ddevicetype(DeviceType),
2637 SourceFormat, debug_d3dformat(SourceFormat),
2638 TargetFormat, debug_d3dformat(TargetFormat));
2639 return WINED3D_OK;
2642 static const shader_backend_t *select_shader_backend(UINT Adapter, WINED3DDEVTYPE DeviceType) {
2643 const shader_backend_t *ret;
2644 int vs_selected_mode;
2645 int ps_selected_mode;
2647 select_shader_mode(&GLINFO_LOCATION, DeviceType, &ps_selected_mode, &vs_selected_mode);
2648 if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) {
2649 ret = &glsl_shader_backend;
2650 } else if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) {
2651 ret = &arb_program_shader_backend;
2652 } else {
2653 ret = &none_shader_backend;
2655 return ret;
2658 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
2659 subset of a D3DCAPS9 structure. However, it has to come via a void *
2660 as the d3d8 interface cannot import the d3d9 header */
2661 static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
2663 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2664 int vs_selected_mode;
2665 int ps_selected_mode;
2666 struct shader_caps shader_caps;
2667 const shader_backend_t *shader_backend;
2669 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
2671 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2672 return WINED3DERR_INVALIDCALL;
2675 select_shader_mode(&Adapters[Adapter].gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
2677 /* This function should *not* be modifying GL caps
2678 * TODO: move the functionality where it belongs */
2679 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &Adapters[Adapter].gl_info);
2681 /* ------------------------------------------------
2682 The following fields apply to both d3d8 and d3d9
2683 ------------------------------------------------ */
2684 pCaps->DeviceType = (DeviceType == WINED3DDEVTYPE_HAL) ? WINED3DDEVTYPE_HAL : WINED3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
2685 pCaps->AdapterOrdinal = Adapter;
2687 pCaps->Caps = 0;
2688 pCaps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
2689 WINED3DCAPS2_FULLSCREENGAMMA |
2690 WINED3DCAPS2_DYNAMICTEXTURES;
2691 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
2692 pCaps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
2694 pCaps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD;
2695 pCaps->PresentationIntervals = WINED3DPRESENT_INTERVAL_IMMEDIATE |
2696 WINED3DPRESENT_INTERVAL_ONE;
2698 pCaps->CursorCaps = WINED3DCURSORCAPS_COLOR |
2699 WINED3DCURSORCAPS_LOWRES;
2701 pCaps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
2702 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
2703 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
2704 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
2705 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
2706 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
2707 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
2708 WINED3DDEVCAPS_PUREDEVICE |
2709 WINED3DDEVCAPS_HWRASTERIZATION |
2710 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
2711 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
2712 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
2713 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
2714 WINED3DDEVCAPS_DRAWPRIMITIVES2EX |
2715 WINED3DDEVCAPS_RTPATCHES;
2717 pCaps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
2718 WINED3DPMISCCAPS_CULLCCW |
2719 WINED3DPMISCCAPS_CULLCW |
2720 WINED3DPMISCCAPS_COLORWRITEENABLE |
2721 WINED3DPMISCCAPS_CLIPTLVERTS |
2722 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
2723 WINED3DPMISCCAPS_MASKZ |
2724 WINED3DPMISCCAPS_BLENDOP;
2725 /* TODO:
2726 WINED3DPMISCCAPS_NULLREFERENCE
2727 WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS
2728 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
2729 WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
2730 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING
2731 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
2733 if(GL_SUPPORT(EXT_BLEND_EQUATION_SEPARATE) && GL_SUPPORT(EXT_BLEND_FUNC_SEPARATE))
2734 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
2736 /* The caps below can be supported but aren't handled yet in utils.c 'd3dta_to_combiner_input', disable them until support is fixed */
2737 #if 0
2738 if (GL_SUPPORT(NV_REGISTER_COMBINERS))
2739 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_TSSARGTEMP;
2740 if (GL_SUPPORT(NV_REGISTER_COMBINERS2))
2741 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_PERSTAGECONSTANT;
2742 #endif
2744 pCaps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
2745 WINED3DPRASTERCAPS_PAT |
2746 WINED3DPRASTERCAPS_WFOG |
2747 WINED3DPRASTERCAPS_ZFOG |
2748 WINED3DPRASTERCAPS_FOGVERTEX |
2749 WINED3DPRASTERCAPS_FOGTABLE |
2750 WINED3DPRASTERCAPS_STIPPLE |
2751 WINED3DPRASTERCAPS_SUBPIXEL |
2752 WINED3DPRASTERCAPS_ZTEST |
2753 WINED3DPRASTERCAPS_SCISSORTEST |
2754 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
2755 WINED3DPRASTERCAPS_DEPTHBIAS;
2757 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2758 pCaps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY |
2759 WINED3DPRASTERCAPS_ZBIAS |
2760 WINED3DPRASTERCAPS_MIPMAPLODBIAS;
2762 if(GL_SUPPORT(NV_FOG_DISTANCE)) {
2763 pCaps->RasterCaps |= WINED3DPRASTERCAPS_FOGRANGE;
2765 /* FIXME Add:
2766 WINED3DPRASTERCAPS_COLORPERSPECTIVE
2767 WINED3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
2768 WINED3DPRASTERCAPS_ANTIALIASEDGES
2769 WINED3DPRASTERCAPS_ZBUFFERLESSHSR
2770 WINED3DPRASTERCAPS_WBUFFER */
2772 pCaps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
2773 WINED3DPCMPCAPS_EQUAL |
2774 WINED3DPCMPCAPS_GREATER |
2775 WINED3DPCMPCAPS_GREATEREQUAL |
2776 WINED3DPCMPCAPS_LESS |
2777 WINED3DPCMPCAPS_LESSEQUAL |
2778 WINED3DPCMPCAPS_NEVER |
2779 WINED3DPCMPCAPS_NOTEQUAL;
2781 pCaps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
2782 WINED3DPBLENDCAPS_BOTHSRCALPHA |
2783 WINED3DPBLENDCAPS_DESTALPHA |
2784 WINED3DPBLENDCAPS_DESTCOLOR |
2785 WINED3DPBLENDCAPS_INVDESTALPHA |
2786 WINED3DPBLENDCAPS_INVDESTCOLOR |
2787 WINED3DPBLENDCAPS_INVSRCALPHA |
2788 WINED3DPBLENDCAPS_INVSRCCOLOR |
2789 WINED3DPBLENDCAPS_ONE |
2790 WINED3DPBLENDCAPS_SRCALPHA |
2791 WINED3DPBLENDCAPS_SRCALPHASAT |
2792 WINED3DPBLENDCAPS_SRCCOLOR |
2793 WINED3DPBLENDCAPS_ZERO;
2795 pCaps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
2796 WINED3DPBLENDCAPS_DESTCOLOR |
2797 WINED3DPBLENDCAPS_INVDESTALPHA |
2798 WINED3DPBLENDCAPS_INVDESTCOLOR |
2799 WINED3DPBLENDCAPS_INVSRCALPHA |
2800 WINED3DPBLENDCAPS_INVSRCCOLOR |
2801 WINED3DPBLENDCAPS_ONE |
2802 WINED3DPBLENDCAPS_SRCALPHA |
2803 WINED3DPBLENDCAPS_SRCCOLOR |
2804 WINED3DPBLENDCAPS_ZERO;
2805 /* NOTE: WINED3DPBLENDCAPS_SRCALPHASAT is not supported as dest blend factor,
2806 * according to the glBlendFunc manpage
2808 * WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA are
2809 * legacy settings for srcblend only
2812 if( GL_SUPPORT(EXT_BLEND_COLOR)) {
2813 pCaps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
2814 pCaps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
2818 pCaps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
2819 WINED3DPCMPCAPS_EQUAL |
2820 WINED3DPCMPCAPS_GREATER |
2821 WINED3DPCMPCAPS_GREATEREQUAL |
2822 WINED3DPCMPCAPS_LESS |
2823 WINED3DPCMPCAPS_LESSEQUAL |
2824 WINED3DPCMPCAPS_NEVER |
2825 WINED3DPCMPCAPS_NOTEQUAL;
2827 pCaps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
2828 WINED3DPSHADECAPS_COLORGOURAUDRGB |
2829 WINED3DPSHADECAPS_ALPHAFLATBLEND |
2830 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
2831 WINED3DPSHADECAPS_COLORFLATRGB |
2832 WINED3DPSHADECAPS_FOGFLAT |
2833 WINED3DPSHADECAPS_FOGGOURAUD |
2834 WINED3DPSHADECAPS_SPECULARFLATRGB;
2836 pCaps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
2837 WINED3DPTEXTURECAPS_ALPHAPALETTE |
2838 WINED3DPTEXTURECAPS_BORDER |
2839 WINED3DPTEXTURECAPS_MIPMAP |
2840 WINED3DPTEXTURECAPS_PROJECTED |
2841 WINED3DPTEXTURECAPS_PERSPECTIVE;
2843 if( !GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
2844 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
2845 WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
2848 if( GL_SUPPORT(EXT_TEXTURE3D)) {
2849 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP |
2850 WINED3DPTEXTURECAPS_MIPVOLUMEMAP |
2851 WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
2854 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2855 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP |
2856 WINED3DPTEXTURECAPS_MIPCUBEMAP |
2857 WINED3DPTEXTURECAPS_CUBEMAP_POW2;
2861 pCaps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2862 WINED3DPTFILTERCAPS_MAGFPOINT |
2863 WINED3DPTFILTERCAPS_MINFLINEAR |
2864 WINED3DPTFILTERCAPS_MINFPOINT |
2865 WINED3DPTFILTERCAPS_MIPFLINEAR |
2866 WINED3DPTFILTERCAPS_MIPFPOINT |
2867 WINED3DPTFILTERCAPS_LINEAR |
2868 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2869 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2870 WINED3DPTFILTERCAPS_MIPLINEAR |
2871 WINED3DPTFILTERCAPS_MIPNEAREST |
2872 WINED3DPTFILTERCAPS_NEAREST;
2874 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2875 pCaps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
2876 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
2879 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
2880 pCaps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2881 WINED3DPTFILTERCAPS_MAGFPOINT |
2882 WINED3DPTFILTERCAPS_MINFLINEAR |
2883 WINED3DPTFILTERCAPS_MINFPOINT |
2884 WINED3DPTFILTERCAPS_MIPFLINEAR |
2885 WINED3DPTFILTERCAPS_MIPFPOINT |
2886 WINED3DPTFILTERCAPS_LINEAR |
2887 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2888 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2889 WINED3DPTFILTERCAPS_MIPLINEAR |
2890 WINED3DPTFILTERCAPS_MIPNEAREST |
2891 WINED3DPTFILTERCAPS_NEAREST;
2893 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
2894 pCaps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
2895 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
2897 } else
2898 pCaps->CubeTextureFilterCaps = 0;
2900 if (GL_SUPPORT(EXT_TEXTURE3D)) {
2901 pCaps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2902 WINED3DPTFILTERCAPS_MAGFPOINT |
2903 WINED3DPTFILTERCAPS_MINFLINEAR |
2904 WINED3DPTFILTERCAPS_MINFPOINT |
2905 WINED3DPTFILTERCAPS_MIPFLINEAR |
2906 WINED3DPTFILTERCAPS_MIPFPOINT |
2907 WINED3DPTFILTERCAPS_LINEAR |
2908 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2909 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2910 WINED3DPTFILTERCAPS_MIPLINEAR |
2911 WINED3DPTFILTERCAPS_MIPNEAREST |
2912 WINED3DPTFILTERCAPS_NEAREST;
2913 } else
2914 pCaps->VolumeTextureFilterCaps = 0;
2916 pCaps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
2917 WINED3DPTADDRESSCAPS_CLAMP |
2918 WINED3DPTADDRESSCAPS_WRAP;
2920 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
2921 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
2923 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
2924 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
2926 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
2927 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
2930 if (GL_SUPPORT(EXT_TEXTURE3D)) {
2931 pCaps->VolumeTextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
2932 WINED3DPTADDRESSCAPS_CLAMP |
2933 WINED3DPTADDRESSCAPS_WRAP;
2934 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
2935 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
2937 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
2938 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
2940 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
2941 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
2943 } else
2944 pCaps->VolumeTextureAddressCaps = 0;
2946 pCaps->LineCaps = WINED3DLINECAPS_TEXTURE |
2947 WINED3DLINECAPS_ZTEST;
2948 /* FIXME: Add
2949 WINED3DLINECAPS_BLEND
2950 WINED3DLINECAPS_ALPHACMP
2951 WINED3DLINECAPS_FOG */
2953 pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
2954 pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
2956 if(GL_SUPPORT(EXT_TEXTURE3D))
2957 pCaps->MaxVolumeExtent = GL_LIMITS(texture3d_size);
2958 else
2959 pCaps->MaxVolumeExtent = 0;
2961 pCaps->MaxTextureRepeat = 32768;
2962 pCaps->MaxTextureAspectRatio = GL_LIMITS(texture_size);
2963 pCaps->MaxVertexW = 1.0;
2965 pCaps->GuardBandLeft = 0;
2966 pCaps->GuardBandTop = 0;
2967 pCaps->GuardBandRight = 0;
2968 pCaps->GuardBandBottom = 0;
2970 pCaps->ExtentsAdjust = 0;
2972 pCaps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
2973 WINED3DSTENCILCAPS_INCRSAT |
2974 WINED3DSTENCILCAPS_INVERT |
2975 WINED3DSTENCILCAPS_KEEP |
2976 WINED3DSTENCILCAPS_REPLACE |
2977 WINED3DSTENCILCAPS_ZERO;
2978 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
2979 pCaps->StencilCaps |= WINED3DSTENCILCAPS_DECR |
2980 WINED3DSTENCILCAPS_INCR;
2982 if ( This->dxVersion > 8 &&
2983 ( GL_SUPPORT(EXT_STENCIL_TWO_SIDE) ||
2984 GL_SUPPORT(ATI_SEPARATE_STENCIL) ) ) {
2985 pCaps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
2988 pCaps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
2990 pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
2991 pCaps->MaxActiveLights = GL_LIMITS(lights);
2993 pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
2994 pCaps->MaxVertexBlendMatrixIndex = 0;
2996 pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
2997 pCaps->MaxPointSize = GL_LIMITS(pointsize);
3000 pCaps->VertexProcessingCaps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
3001 WINED3DVTXPCAPS_MATERIALSOURCE7 |
3002 WINED3DVTXPCAPS_POSITIONALLIGHTS |
3003 WINED3DVTXPCAPS_LOCALVIEWER |
3004 WINED3DVTXPCAPS_VERTEXFOG |
3005 WINED3DVTXPCAPS_TEXGEN;
3006 /* FIXME: Add
3007 D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
3009 pCaps->MaxPrimitiveCount = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
3010 pCaps->MaxVertexIndex = 0xFFFFF;
3011 pCaps->MaxStreams = MAX_STREAMS;
3012 pCaps->MaxStreamStride = 1024;
3014 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
3015 pCaps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET;
3016 /* TODO: VS3.0 needs at least D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET */
3017 pCaps->MaxNpatchTessellationLevel = 0;
3018 pCaps->MasterAdapterOrdinal = 0;
3019 pCaps->AdapterOrdinalInGroup = 0;
3020 pCaps->NumberOfAdaptersInGroup = 1;
3022 pCaps->NumSimultaneousRTs = GL_LIMITS(buffers);
3024 pCaps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
3025 WINED3DPTFILTERCAPS_MAGFPOINT |
3026 WINED3DPTFILTERCAPS_MINFLINEAR |
3027 WINED3DPTFILTERCAPS_MAGFLINEAR;
3028 pCaps->VertexTextureFilterCaps = 0;
3030 memset(&shader_caps, 0, sizeof(shader_caps));
3031 shader_backend = select_shader_backend(Adapter, DeviceType);
3032 shader_backend->shader_get_caps(DeviceType, &GLINFO_LOCATION, &shader_caps);
3034 /* This takes care for disabling vertex shader or pixel shader caps while leaving the other one enabled.
3035 * Ignore shader model capabilities if disabled in config
3037 if(vs_selected_mode == SHADER_NONE) {
3038 TRACE_(d3d_caps)("Vertex shader disabled in config, reporting version 0.0\n");
3039 pCaps->VertexShaderVersion = WINED3DVS_VERSION(0,0);
3040 pCaps->MaxVertexShaderConst = 0;
3041 } else {
3042 pCaps->VertexShaderVersion = shader_caps.VertexShaderVersion;
3043 pCaps->MaxVertexShaderConst = shader_caps.MaxVertexShaderConst;
3046 if(ps_selected_mode == SHADER_NONE) {
3047 TRACE_(d3d_caps)("Pixel shader disabled in config, reporting version 0.0\n");
3048 pCaps->PixelShaderVersion = WINED3DPS_VERSION(0,0);
3049 pCaps->PixelShader1xMaxValue = 0.0;
3050 } else {
3051 pCaps->PixelShaderVersion = shader_caps.PixelShaderVersion;
3052 pCaps->PixelShader1xMaxValue = shader_caps.PixelShader1xMaxValue;
3055 pCaps->TextureOpCaps = shader_caps.TextureOpCaps;
3056 pCaps->MaxTextureBlendStages = shader_caps.MaxTextureBlendStages;
3057 pCaps->MaxSimultaneousTextures = shader_caps.MaxSimultaneousTextures;
3058 pCaps->VS20Caps = shader_caps.VS20Caps;
3059 pCaps->MaxVShaderInstructionsExecuted = shader_caps.MaxVShaderInstructionsExecuted;
3060 pCaps->MaxVertexShader30InstructionSlots= shader_caps.MaxVertexShader30InstructionSlots;
3061 pCaps->PS20Caps = shader_caps.PS20Caps;
3062 pCaps->MaxPShaderInstructionsExecuted = shader_caps.MaxPShaderInstructionsExecuted;
3063 pCaps->MaxPixelShader30InstructionSlots = shader_caps.MaxPixelShader30InstructionSlots;
3065 /* The following caps are shader specific, but they are things we cannot detect, or which
3066 * are the same among all shader models. So to avoid code duplication set the shader version
3067 * specific, but otherwise constant caps here
3069 if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(3,0)) {
3070 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
3071 use the VS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum VS3.0 value. */
3072 pCaps->VS20Caps.Caps = WINED3DVS20CAPS_PREDICATION;
3073 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
3074 pCaps->VS20Caps.NumTemps = max(32, GLINFO_LOCATION.vs_arb_max_temps);
3075 pCaps->VS20Caps.StaticFlowControlDepth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH ; /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
3077 pCaps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
3078 pCaps->MaxVertexShader30InstructionSlots = max(512, GLINFO_LOCATION.vs_arb_max_instructions);
3079 } else if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(2,0)) {
3080 pCaps->VS20Caps.Caps = 0;
3081 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
3082 pCaps->VS20Caps.NumTemps = max(12, GLINFO_LOCATION.vs_arb_max_temps);
3083 pCaps->VS20Caps.StaticFlowControlDepth = 1;
3085 pCaps->MaxVShaderInstructionsExecuted = 65535;
3086 pCaps->MaxVertexShader30InstructionSlots = 0;
3087 } else { /* VS 1.x */
3088 pCaps->VS20Caps.Caps = 0;
3089 pCaps->VS20Caps.DynamicFlowControlDepth = 0;
3090 pCaps->VS20Caps.NumTemps = 0;
3091 pCaps->VS20Caps.StaticFlowControlDepth = 0;
3093 pCaps->MaxVShaderInstructionsExecuted = 0;
3094 pCaps->MaxVertexShader30InstructionSlots = 0;
3097 if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(3,0)) {
3098 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
3099 use the PS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum PS 3.0 value. */
3101 /* 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 */
3102 pCaps->PS20Caps.Caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
3103 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
3104 WINED3DPS20CAPS_PREDICATION |
3105 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
3106 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
3107 pCaps->PS20Caps.DynamicFlowControlDepth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
3108 pCaps->PS20Caps.NumTemps = max(32, GLINFO_LOCATION.ps_arb_max_temps);
3109 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
3110 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
3112 pCaps->MaxPShaderInstructionsExecuted = 65535;
3113 pCaps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS, GLINFO_LOCATION.ps_arb_max_instructions);
3114 } else if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(2,0)) {
3115 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
3116 pCaps->PS20Caps.Caps = 0;
3117 pCaps->PS20Caps.DynamicFlowControlDepth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
3118 pCaps->PS20Caps.NumTemps = max(12, GLINFO_LOCATION.ps_arb_max_temps);
3119 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
3120 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
3122 pCaps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
3123 pCaps->MaxPixelShader30InstructionSlots = 0;
3124 } else { /* PS 1.x */
3125 pCaps->PS20Caps.Caps = 0;
3126 pCaps->PS20Caps.DynamicFlowControlDepth = 0;
3127 pCaps->PS20Caps.NumTemps = 0;
3128 pCaps->PS20Caps.StaticFlowControlDepth = 0;
3129 pCaps->PS20Caps.NumInstructionSlots = 0;
3131 pCaps->MaxPShaderInstructionsExecuted = 0;
3132 pCaps->MaxPixelShader30InstructionSlots = 0;
3135 if(pCaps->VertexShaderVersion >= WINED3DVS_VERSION(2,0)) {
3136 /* OpenGL supports all the formats below, perhaps not always
3137 * without conversion, but it supports them.
3138 * Further GLSL doesn't seem to have an official unsigned type so
3139 * don't advertise it yet as I'm not sure how we handle it.
3140 * We might need to add some clamping in the shader engine to
3141 * support it.
3142 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
3143 pCaps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
3144 WINED3DDTCAPS_UBYTE4N |
3145 WINED3DDTCAPS_SHORT2N |
3146 WINED3DDTCAPS_SHORT4N;
3147 if (GL_SUPPORT(NV_HALF_FLOAT)) {
3148 pCaps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
3149 WINED3DDTCAPS_FLOAT16_4;
3151 } else
3152 pCaps->DeclTypes = 0;
3154 return WINED3D_OK;
3157 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
3158 and fields being inserted in the middle, a new structure is used in place */
3159 static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, HWND hFocusWindow,
3160 DWORD BehaviourFlags, IWineD3DDevice** ppReturnedDeviceInterface,
3161 IUnknown *parent) {
3163 IWineD3DDeviceImpl *object = NULL;
3164 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3165 WINED3DDISPLAYMODE mode;
3166 int i;
3168 /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
3169 * number and create a device without a 3D adapter for 2D only operation.
3171 if (IWineD3D_GetAdapterCount(iface) && Adapter >= IWineD3D_GetAdapterCount(iface)) {
3172 return WINED3DERR_INVALIDCALL;
3175 /* Create a WineD3DDevice object */
3176 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
3177 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
3178 TRACE("Created WineD3DDevice object @ %p\n", object);
3179 if (NULL == object) {
3180 return WINED3DERR_OUTOFVIDEOMEMORY;
3183 /* Set up initial COM information */
3184 object->lpVtbl = &IWineD3DDevice_Vtbl;
3185 object->ref = 1;
3186 object->wineD3D = iface;
3187 object->adapter = numAdapters ? &Adapters[Adapter] : NULL;
3188 IWineD3D_AddRef(object->wineD3D);
3189 object->parent = parent;
3190 list_init(&object->resources);
3191 list_init(&object->shaders);
3193 if(This->dxVersion == 7) {
3194 object->surface_alignment = 8;
3195 } else {
3196 object->surface_alignment = 4;
3198 object->posFixup[0] = 1.0; /* This is needed to get the x coord unmodified through a MAD */
3200 /* Set the state up as invalid until the device is fully created */
3201 object->state = WINED3DERR_DRIVERINTERNALERROR;
3203 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %x, RetDevInt: %p)\n", This, Adapter, DeviceType,
3204 hFocusWindow, BehaviourFlags, ppReturnedDeviceInterface);
3206 /* Save the creation parameters */
3207 object->createParms.AdapterOrdinal = Adapter;
3208 object->createParms.DeviceType = DeviceType;
3209 object->createParms.hFocusWindow = hFocusWindow;
3210 object->createParms.BehaviorFlags = BehaviourFlags;
3212 /* Initialize other useful values */
3213 object->adapterNo = Adapter;
3214 object->devType = DeviceType;
3216 select_shader_mode(&GLINFO_LOCATION, DeviceType, &object->ps_selected_mode, &object->vs_selected_mode);
3217 object->shader_backend = select_shader_backend(Adapter, DeviceType);
3219 /* Prefer the vtable with functions optimized for single dirtifyable objects if the shader
3220 * model can deal with that. It is essentially the same, just with adjusted
3221 * Set*ShaderConstantF implementations
3223 if(object->shader_backend->shader_dirtifyable_constants((IWineD3DDevice *) object)) {
3224 object->lpVtbl = &IWineD3DDevice_DirtyConst_Vtbl;
3227 /* set the state of the device to valid */
3228 object->state = WINED3D_OK;
3230 /* Get the initial screen setup for ddraw */
3231 IWineD3DImpl_GetAdapterDisplayMode(iface, Adapter, &mode);
3233 object->ddraw_width = mode.Width;
3234 object->ddraw_height = mode.Height;
3235 object->ddraw_format = mode.Format;
3237 for(i = 0; i < PATCHMAP_SIZE; i++) {
3238 list_init(&object->patches[i]);
3240 return WINED3D_OK;
3242 #undef GLINFO_LOCATION
3244 static HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
3245 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3246 IUnknown_AddRef(This->parent);
3247 *pParent = This->parent;
3248 return WINED3D_OK;
3251 ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface) {
3252 IUnknown* surfaceParent;
3253 TRACE("(%p) call back\n", pSurface);
3255 /* Now, release the parent, which will take care of cleaning up the surface for us */
3256 IWineD3DSurface_GetParent(pSurface, &surfaceParent);
3257 IUnknown_Release(surfaceParent);
3258 return IUnknown_Release(surfaceParent);
3261 ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pVolume) {
3262 IUnknown* volumeParent;
3263 TRACE("(%p) call back\n", pVolume);
3265 /* Now, release the parent, which will take care of cleaning up the volume for us */
3266 IWineD3DVolume_GetParent(pVolume, &volumeParent);
3267 IUnknown_Release(volumeParent);
3268 return IUnknown_Release(volumeParent);
3271 static BOOL implementation_is_apple(WineD3D_GL_Info *gl_info) {
3272 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
3273 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
3274 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
3276 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
3277 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
3278 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
3279 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
3280 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
3281 * the chance that other implementations support them is rather small since Win32 QuickTime uses
3282 * DirectDraw, not OpenGL.
3284 if(gl_info->supported[APPLE_FENCE] &&
3285 gl_info->supported[APPLE_CLIENT_STORAGE] &&
3286 gl_info->supported[APPLE_FLUSH_RENDER] &&
3287 gl_info->supported[APPLE_YCBCR_422]) {
3288 TRACE_(d3d_caps)("GL_APPLE_fence, GL_APPLE_client_storage, GL_APPLE_flush_render and GL_ycbcr_422 are supported\n");
3289 TRACE_(d3d_caps)("Activating MacOS fixups\n");
3290 return TRUE;
3291 } else {
3292 TRACE_(d3d_caps)("Apple extensions are not supported\n");
3293 TRACE_(d3d_caps)("Not activating MacOS fixups\n");
3294 return FALSE;
3298 #define GLINFO_LOCATION (*gl_info)
3299 static void test_pbo_functionality(WineD3D_GL_Info *gl_info) {
3300 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
3301 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
3302 * all the texture. This function detects this bug by its symptom and disables PBOs
3303 * if the test fails.
3305 * The test uplaods a 4x4 texture via the PBO in the "native" format GL_BGRA,
3306 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
3307 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
3308 * read back is compared to the original. If they are equal PBOs are assumed to work,
3309 * otherwise the PBO extension is disabled.
3311 GLuint texture, pbo;
3312 static const unsigned int pattern[] = {
3313 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
3314 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
3315 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
3316 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
3318 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
3320 if(!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) {
3321 /* No PBO -> No point in testing them */
3322 return;
3325 while(glGetError());
3326 glGenTextures(1, &texture);
3327 glBindTexture(GL_TEXTURE_2D, texture);
3328 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
3329 checkGLcall("Specifying the PBO test texture\n");
3331 GL_EXTCALL(glGenBuffersARB(1, &pbo));
3332 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
3333 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
3334 checkGLcall("Specifying the PBO test pbo\n");
3336 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
3337 checkGLcall("Loading the PBO test texture\n");
3339 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
3340 glFinish(); /* just to be sure */
3342 memset(check, 0, sizeof(check));
3343 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
3344 checkGLcall("Reading back the PBO test texture\n");
3346 glDeleteTextures(1, &texture);
3347 GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
3348 checkGLcall("PBO test cleanup\n");
3350 if(memcmp(check, pattern, sizeof(check)) != 0) {
3351 WARN_(d3d_caps)("PBO test failed, read back data doesn't match original\n");
3352 WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance\n");
3353 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
3354 } else {
3355 TRACE_(d3d_caps)("PBO test successful\n");
3358 #undef GLINFO_LOCATION
3360 /* Certain applications(Steam) complain if we report an outdated driver version. In general,
3361 * reporting a driver version is moot because we are not the Windows driver, and we have different
3362 * bugs, features, etc.
3364 * If a card is not found in this table, the gl driver version is reported
3366 struct driver_version_information {
3367 WORD vendor; /* reported PCI card vendor ID */
3368 WORD card; /* reported PCI card device ID */
3369 WORD hipart_hi, hipart_lo; /* driver hiword to report */
3370 WORD lopart_hi, lopart_lo; /* driver loword to report */
3373 static const struct driver_version_information driver_version_table[] = {
3374 /* Nvidia drivers. Geforce FX and newer cards are supported by the current driver */
3375 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, 7, 15, 10, 16921 },
3376 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, 7, 15, 10, 16921 },
3377 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, 7, 15, 10, 16921 },
3378 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, 7, 15, 10, 16921 },
3379 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, 7, 15, 10, 16921 },
3380 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, 7, 15, 10, 16921 },
3381 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, 7, 15, 10, 16921 },
3382 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, 7, 15, 10, 16921 },
3383 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, 7, 15, 10, 16921 },
3384 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, 7, 15, 10, 16921 },
3385 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, 7, 15, 10, 16921 },
3386 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, 7, 15, 10, 16921 },
3387 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, 7, 15, 10, 16921 },
3388 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, 7, 15, 10, 16921 },
3390 /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode */
3391 {VENDOR_ATI, CARD_ATI_RADEON_9500, 6, 14, 10, 6764 },
3392 {VENDOR_ATI, CARD_ATI_RADEON_X700, 6, 14, 10, 6764 },
3393 {VENDOR_ATI, CARD_ATI_RADEON_X1600, 6, 14, 10, 6764 },
3394 {VENDOR_ATI, CARD_ATI_RADEON_HD2300, 6, 14, 10, 6764 },
3395 {VENDOR_ATI, CARD_ATI_RADEON_HD2600, 6, 14, 10, 6764 },
3396 {VENDOR_ATI, CARD_ATI_RADEON_HD2900, 6, 14, 10, 6764 },
3398 /* TODO: Add information about legacy nvidia and ATI hardware, Intel and other cards */
3401 static void fixup_extensions(WineD3D_GL_Info *gl_info) {
3402 unsigned int i;
3403 BOOL apple = implementation_is_apple(gl_info);
3405 if(apple) {
3406 /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
3407 * used it falls back to software. While the compiler can detect if the shader uses all declared
3408 * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
3409 * using relative addressing falls back to software.
3411 * ARB vp gives the correct amount of uniforms, so use it instead of GLSL
3413 if(gl_info->vs_glsl_constantsF <= gl_info->vs_arb_constantsF) {
3414 FIXME("GLSL doesn't advertise more vertex shader uniforms than ARB. Driver fixup outdated?\n");
3415 } else {
3416 TRACE("Driver claims %u GLSL vs uniforms, replacing with %u ARB vp uniforms\n",
3417 gl_info->vs_glsl_constantsF, gl_info->vs_arb_constantsF);
3418 gl_info->vs_glsl_constantsF = gl_info->vs_arb_constantsF;
3421 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
3422 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
3423 * If real NP2 textures are used, the driver falls back to software. So remove the supported
3424 * flag for this extension
3426 if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] && gl_info->gl_vendor == VENDOR_ATI) {
3427 if(gl_info->gl_card == CARD_ATI_RADEON_X700 || gl_info->gl_card == CARD_ATI_RADEON_X1600 ||
3428 gl_info->gl_card == CARD_ATI_RADEON_9500 || gl_info->gl_card == CARD_ATI_RADEON_8500 ||
3429 gl_info->gl_card == CARD_ATI_RADEON_7200 || gl_info->gl_card == CARD_ATI_RAGE_128PRO) {
3430 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing\n");
3431 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
3432 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
3436 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
3437 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
3438 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
3439 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
3440 * according to the spec.
3442 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
3443 * makes the shader slower and eats instruction slots which should be available to the d3d app.
3445 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
3446 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
3447 * this workaround is activated on cards that do not need it, it won't break things, just affect
3448 * performance negatively.
3450 if(gl_info->gl_vendor == VENDOR_INTEL ||
3451 (gl_info->gl_vendor == VENDOR_ATI && gl_info->gl_card != CARD_ATI_RADEON_X1600)) {
3452 TRACE("Enabling vertex texture coord fixes in vertex shaders\n");
3453 gl_info->set_texcoord_w = TRUE;
3457 /* Find out if PBOs work as they are supposed to */
3458 test_pbo_functionality(gl_info);
3460 /* Fixup the driver version */
3461 for(i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++) {
3462 if(gl_info->gl_vendor == driver_version_table[i].vendor &&
3463 gl_info->gl_card == driver_version_table[i].card) {
3464 TRACE_(d3d_caps)("Found card 0x%04x, 0x%04x in driver version DB\n", gl_info->gl_vendor, gl_info->gl_card);
3466 gl_info->driver_version = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
3467 driver_version_table[i].lopart_lo);
3468 gl_info->driver_version_hipart = MAKEDWORD_VERSION(driver_version_table[i].hipart_hi,
3469 driver_version_table[i].hipart_lo);
3470 break;
3475 void invalid_func(void *data) {
3476 ERR("Invalid vertex attribute function called\n");
3477 DebugBreak();
3480 #define GLINFO_LOCATION (Adapters[0].gl_info)
3482 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
3483 * the extension detection and are used in drawStridedSlow
3485 static void position_d3dcolor(void *data) {
3486 DWORD pos = *((DWORD *) data);
3488 FIXME("Add a test for fixed function position from d3dcolor type\n");
3489 glVertex4s(D3DCOLOR_B_R(pos),
3490 D3DCOLOR_B_G(pos),
3491 D3DCOLOR_B_B(pos),
3492 D3DCOLOR_B_A(pos));
3494 static void position_float4(void *data) {
3495 GLfloat *pos = (float *) data;
3497 if (pos[3] < eps && pos[3] > -eps)
3498 glVertex3fv(pos);
3499 else {
3500 float w = 1.0 / pos[3];
3502 glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
3506 static void diffuse_d3dcolor(void *data) {
3507 DWORD diffuseColor = *((DWORD *) data);
3509 glColor4ub(D3DCOLOR_B_R(diffuseColor),
3510 D3DCOLOR_B_G(diffuseColor),
3511 D3DCOLOR_B_B(diffuseColor),
3512 D3DCOLOR_B_A(diffuseColor));
3515 static void specular_d3dcolor(void *data) {
3516 DWORD specularColor = *((DWORD *) data);
3518 GL_EXTCALL(glSecondaryColor3ubEXT)(D3DCOLOR_B_R(specularColor),
3519 D3DCOLOR_B_G(specularColor),
3520 D3DCOLOR_B_B(specularColor));
3522 static void warn_no_specular_func(void *data) {
3523 WARN("GL_EXT_secondary_color not supported\n");
3526 void fillGLAttribFuncs(WineD3D_GL_Info *gl_info) {
3527 position_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3528 position_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3529 position_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glVertex3fv;
3530 position_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) position_float4;
3531 position_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) position_d3dcolor;
3532 position_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3533 position_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3534 position_funcs[WINED3DDECLTYPE_SHORT4] = (void *) glVertex2sv;
3535 position_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3536 position_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3537 position_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3538 position_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3539 position_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3540 position_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3541 position_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3542 position_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3543 position_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3545 diffuse_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3546 diffuse_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3547 diffuse_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glColor3fv;
3548 diffuse_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) glColor4fv;
3549 diffuse_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) diffuse_d3dcolor;
3550 diffuse_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3551 diffuse_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3552 diffuse_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3553 diffuse_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) glColor4ubv;
3554 diffuse_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3555 diffuse_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) glColor4sv;
3556 diffuse_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3557 diffuse_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) glColor4usv;
3558 diffuse_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3559 diffuse_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3560 diffuse_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3561 diffuse_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3563 /* No 4 component entry points here */
3564 specular_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3565 specular_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3566 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
3567 specular_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) GL_EXTCALL(glSecondaryColor3fvEXT);
3568 } else {
3569 specular_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) warn_no_specular_func;
3571 specular_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) invalid_func;
3572 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
3573 specular_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) specular_d3dcolor;
3574 } else {
3575 specular_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) warn_no_specular_func;
3577 specular_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3578 specular_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3579 specular_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3580 specular_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3581 specular_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3582 specular_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3583 specular_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3584 specular_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3585 specular_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3586 specular_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3587 specular_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3588 specular_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3590 /* Only 3 component entry points here. Test how others behave. Float4 normals are used
3591 * by one of our tests, trying to pass it to the pixel shader, which fails on Windows.
3593 normal_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) invalid_func;
3594 normal_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) invalid_func;
3595 normal_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glNormal3fv;
3596 normal_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) glNormal3fv; /* Just ignore the 4th value */
3597 normal_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) invalid_func;
3598 normal_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func;
3599 normal_funcs[WINED3DDECLTYPE_SHORT2] = (void *) invalid_func;
3600 normal_funcs[WINED3DDECLTYPE_SHORT4] = (void *) invalid_func;
3601 normal_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func;
3602 normal_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func;
3603 normal_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func;
3604 normal_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func;
3605 normal_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func;
3606 normal_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func;
3607 normal_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func;
3608 normal_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func;
3609 normal_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func;
3612 #define PUSH1(att) attribs[nAttribs++] = (att);
3613 BOOL InitAdapters(void) {
3614 static HMODULE mod_gl;
3615 BOOL ret;
3616 int ps_selected_mode, vs_selected_mode;
3618 /* No need to hold any lock. The calling library makes sure only one thread calls
3619 * wined3d simultaneously
3621 if(numAdapters > 0) return TRUE;
3623 TRACE("Initializing adapters\n");
3625 if(!mod_gl) {
3626 #ifdef USE_WIN32_OPENGL
3627 #define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
3628 mod_gl = LoadLibraryA("opengl32.dll");
3629 if(!mod_gl) {
3630 ERR("Can't load opengl32.dll!\n");
3631 return FALSE;
3633 #else
3634 #define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
3635 /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
3636 mod_gl = GetModuleHandleA("gdi32.dll");
3637 #endif
3640 /* Load WGL core functions from opengl32.dll */
3641 #define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn);
3642 WGL_FUNCS_GEN;
3643 #undef USE_WGL_FUNC
3645 if(!pwglGetProcAddress) {
3646 ERR("Unable to load wglGetProcAddress!\n");
3647 return FALSE;
3650 /* Dynamically load all GL core functions */
3651 GL_FUNCS_GEN;
3652 #undef USE_GL_FUNC
3654 /* For now only one default adapter */
3656 int iPixelFormat;
3657 int attribs[8];
3658 int values[8];
3659 int nAttribs = 0;
3660 int res;
3661 WineD3D_PixelFormat *cfgs;
3662 int attribute;
3663 DISPLAY_DEVICEW DisplayDevice;
3664 HDC hdc;
3666 TRACE("Initializing default adapter\n");
3667 Adapters[0].num = 0;
3668 Adapters[0].monitorPoint.x = -1;
3669 Adapters[0].monitorPoint.y = -1;
3671 if (!WineD3D_CreateFakeGLContext()) {
3672 ERR("Failed to get a gl context for default adapter\n");
3673 HeapFree(GetProcessHeap(), 0, Adapters);
3674 WineD3D_ReleaseFakeGLContext();
3675 return FALSE;
3678 ret = IWineD3DImpl_FillGLCaps(&Adapters[0].gl_info);
3679 if(!ret) {
3680 ERR("Failed to initialize gl caps for default adapter\n");
3681 HeapFree(GetProcessHeap(), 0, Adapters);
3682 WineD3D_ReleaseFakeGLContext();
3683 return FALSE;
3685 ret = initPixelFormats(&Adapters[0].gl_info);
3686 if(!ret) {
3687 ERR("Failed to init gl formats\n");
3688 HeapFree(GetProcessHeap(), 0, Adapters);
3689 WineD3D_ReleaseFakeGLContext();
3690 return FALSE;
3693 hdc = pwglGetCurrentDC();
3694 if(!hdc) {
3695 ERR("Failed to get gl HDC\n");
3696 HeapFree(GetProcessHeap(), 0, Adapters);
3697 WineD3D_ReleaseFakeGLContext();
3698 return FALSE;
3701 Adapters[0].driver = "Display";
3702 Adapters[0].description = "Direct3D HAL";
3704 /* Use the VideoRamSize registry setting when set */
3705 if(wined3d_settings.emulated_textureram)
3706 Adapters[0].TextureRam = wined3d_settings.emulated_textureram;
3707 else
3708 Adapters[0].TextureRam = Adapters[0].gl_info.vidmem;
3709 Adapters[0].UsedTextureRam = 0;
3710 TRACE("Emulating %dMB of texture ram\n", Adapters[0].TextureRam/(1024*1024));
3712 /* Initialize the Adapter's DeviceName which is required for ChangeDisplaySettings and friends */
3713 DisplayDevice.cb = sizeof(DisplayDevice);
3714 EnumDisplayDevicesW(NULL, 0 /* Adapter 0 = iDevNum 0 */, &DisplayDevice, 0);
3715 TRACE("DeviceName: %s\n", debugstr_w(DisplayDevice.DeviceName));
3716 strcpyW(Adapters[0].DeviceName, DisplayDevice.DeviceName);
3718 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
3719 GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, &attribute, &Adapters[0].nCfgs));
3721 Adapters[0].cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Adapters[0].nCfgs *sizeof(WineD3D_PixelFormat));
3722 cfgs = Adapters[0].cfgs;
3723 PUSH1(WGL_RED_BITS_ARB)
3724 PUSH1(WGL_GREEN_BITS_ARB)
3725 PUSH1(WGL_BLUE_BITS_ARB)
3726 PUSH1(WGL_ALPHA_BITS_ARB)
3727 PUSH1(WGL_DEPTH_BITS_ARB)
3728 PUSH1(WGL_STENCIL_BITS_ARB)
3729 PUSH1(WGL_DRAW_TO_WINDOW_ARB)
3730 PUSH1(WGL_PIXEL_TYPE_ARB)
3732 for(iPixelFormat=1; iPixelFormat<=Adapters[0].nCfgs; iPixelFormat++) {
3733 res = GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, nAttribs, attribs, values));
3735 if(!res)
3736 continue;
3738 /* Cache the pixel format */
3739 cfgs->iPixelFormat = iPixelFormat;
3740 cfgs->redSize = values[0];
3741 cfgs->greenSize = values[1];
3742 cfgs->blueSize = values[2];
3743 cfgs->alphaSize = values[3];
3744 cfgs->depthSize = values[4];
3745 cfgs->stencilSize = values[5];
3746 cfgs->windowDrawable = values[6];
3747 cfgs->iPixelType = values[7];
3749 cfgs->pbufferDrawable = FALSE;
3750 /* Check for pbuffer support when it is around as wglGetPixelFormatAttribiv fails for unknown
3751 attributes. */
3752 if(GL_SUPPORT(WGL_ARB_PBUFFER)) {
3753 int attrib = WGL_DRAW_TO_PBUFFER_ARB;
3754 int value;
3755 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 1, &attrib, &value)))
3756 cfgs->pbufferDrawable = value;
3759 TRACE("iPixelFormat=%d, iPixelType=%#x, RGBA=%d/%d/%d/%d, depth=%d, stencil=%d, windowDrawable=%d, pbufferDrawable=%d\n", cfgs->iPixelFormat, cfgs->iPixelType, cfgs->redSize, cfgs->greenSize, cfgs->blueSize, cfgs->alphaSize, cfgs->depthSize, cfgs->stencilSize, cfgs->windowDrawable, cfgs->pbufferDrawable);
3760 cfgs++;
3763 fixup_extensions(&Adapters[0].gl_info);
3765 WineD3D_ReleaseFakeGLContext();
3767 select_shader_mode(&Adapters[0].gl_info, WINED3DDEVTYPE_HAL, &ps_selected_mode, &vs_selected_mode);
3768 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &Adapters[0].gl_info);
3769 fillGLAttribFuncs(&Adapters[0].gl_info);
3770 init_type_lookup(&Adapters[0].gl_info);
3772 numAdapters = 1;
3773 TRACE("%d adapters successfully initialized\n", numAdapters);
3775 return TRUE;
3777 #undef PUSH1
3778 #undef GLINFO_LOCATION
3780 /**********************************************************
3781 * IWineD3D VTbl follows
3782 **********************************************************/
3784 const IWineD3DVtbl IWineD3D_Vtbl =
3786 /* IUnknown */
3787 IWineD3DImpl_QueryInterface,
3788 IWineD3DImpl_AddRef,
3789 IWineD3DImpl_Release,
3790 /* IWineD3D */
3791 IWineD3DImpl_GetParent,
3792 IWineD3DImpl_GetAdapterCount,
3793 IWineD3DImpl_RegisterSoftwareDevice,
3794 IWineD3DImpl_GetAdapterMonitor,
3795 IWineD3DImpl_GetAdapterModeCount,
3796 IWineD3DImpl_EnumAdapterModes,
3797 IWineD3DImpl_GetAdapterDisplayMode,
3798 IWineD3DImpl_GetAdapterIdentifier,
3799 IWineD3DImpl_CheckDeviceMultiSampleType,
3800 IWineD3DImpl_CheckDepthStencilMatch,
3801 IWineD3DImpl_CheckDeviceType,
3802 IWineD3DImpl_CheckDeviceFormat,
3803 IWineD3DImpl_CheckDeviceFormatConversion,
3804 IWineD3DImpl_GetDeviceCaps,
3805 IWineD3DImpl_CreateDevice