Provide looser device matching for backbuffer and depth buffer
[wine/wine64.git] / dlls / wined3d / directx.c
blobda9ff0763022d13e403818d8ce7c1aa7a264377c
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* Compile time diagnostics: */
26 /* Uncomment this to force only a single display mode to be exposed: */
27 /*#define DEBUG_SINGLE_MODE*/
30 #include "config.h"
31 #include "wined3d_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
34 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
35 #define GLINFO_LOCATION This->gl_info
37 /**********************************************************
38 * Utility functions follow
39 **********************************************************/
41 /* x11drv GDI escapes */
42 #define X11DRV_ESCAPE 6789
43 enum x11drv_escape_codes
45 X11DRV_GET_DISPLAY, /* get X11 display for a DC */
46 X11DRV_GET_DRAWABLE, /* get current drawable for a DC */
47 X11DRV_GET_FONT, /* get current X font for a DC */
50 /* retrieve the X display to use on a given DC */
51 inline static Display *get_display( HDC hdc )
53 Display *display;
54 enum x11drv_escape_codes escape = X11DRV_GET_DISPLAY;
56 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
57 sizeof(display), (LPSTR)&display )) display = NULL;
58 return display;
61 /* lookup tables */
62 int minLookup[MAX_LOOKUPS];
63 int maxLookup[MAX_LOOKUPS];
64 DWORD *stateLookup[MAX_LOOKUPS];
66 DWORD minMipLookup[D3DTEXF_ANISOTROPIC + 1][D3DTEXF_LINEAR + 1];
70 /**
71 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created
72 * ie there is no GL Context - Get a default rendering context to enable the
73 * function query some info from GL
75 static WineD3D_Context* WineD3D_CreateFakeGLContext(void) {
76 static WineD3D_Context ctx = { NULL, NULL, NULL, 0, 0 };
77 WineD3D_Context* ret = NULL;
79 if (glXGetCurrentContext() == NULL) {
80 BOOL gotContext = FALSE;
81 BOOL created = FALSE;
82 XVisualInfo template;
83 HDC device_context;
84 Visual* visual;
85 BOOL failed = FALSE;
86 int num;
87 XWindowAttributes win_attr;
89 TRACE_(d3d_caps)("Creating Fake GL Context\n");
91 ctx.drawable = (Drawable) GetPropA(GetDesktopWindow(), "__wine_x11_whole_window");
93 /* Get the display */
94 device_context = GetDC(0);
95 ctx.display = get_display(device_context);
96 ReleaseDC(0, device_context);
98 /* Get the X visual */
99 ENTER_GL();
100 if (XGetWindowAttributes(ctx.display, ctx.drawable, &win_attr)) {
101 visual = win_attr.visual;
102 } else {
103 visual = DefaultVisual(ctx.display, DefaultScreen(ctx.display));
105 template.visualid = XVisualIDFromVisual(visual);
106 ctx.visInfo = XGetVisualInfo(ctx.display, VisualIDMask, &template, &num);
107 if (ctx.visInfo == NULL) {
108 LEAVE_GL();
109 WARN_(d3d_caps)("Error creating visual info for capabilities initialization\n");
110 failed = TRUE;
113 /* Create a GL context */
114 if (!failed) {
115 ctx.glCtx = glXCreateContext(ctx.display, ctx.visInfo, NULL, GL_TRUE);
117 if (ctx.glCtx == NULL) {
118 LEAVE_GL();
119 WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
120 failed = TRUE;
124 /* Make it the current GL context */
125 if (!failed && glXMakeCurrent(ctx.display, ctx.drawable, ctx.glCtx) == False) {
126 glXDestroyContext(ctx.display, ctx.glCtx);
127 LEAVE_GL();
128 WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
129 failed = TRUE;
132 /* It worked! Wow... */
133 if (!failed) {
134 gotContext = TRUE;
135 created = TRUE;
136 ret = &ctx;
137 } else {
138 ret = NULL;
141 } else {
142 if (ctx.ref > 0) ret = &ctx;
145 if (NULL != ret) InterlockedIncrement(&ret->ref);
146 return ret;
149 static void WineD3D_ReleaseFakeGLContext(WineD3D_Context* ctx) {
150 /* If we created a dummy context, throw it away */
151 if (NULL != ctx) {
152 if (0 == InterlockedDecrement(&ctx->ref)) {
153 glXMakeCurrent(ctx->display, None, NULL);
154 glXDestroyContext(ctx->display, ctx->glCtx);
155 ctx->display = NULL;
156 ctx->glCtx = NULL;
157 LEAVE_GL();
162 /**********************************************************
163 * IUnknown parts follows
164 **********************************************************/
166 HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
168 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
169 /* FIXME: This needs to extend an IWineD3DBaseObject */
171 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
172 if (IsEqualGUID(riid, &IID_IUnknown)
173 || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
174 IUnknown_AddRef(iface);
175 *ppobj = This;
176 return D3D_OK;
179 return E_NOINTERFACE;
182 ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
183 IWineD3DImpl *This = (IWineD3DImpl *)iface;
184 ULONG refCount = InterlockedIncrement(&This->ref);
186 TRACE("(%p) : AddRef increasing from %ld\n", This, refCount - 1);
187 return refCount;
190 ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
191 IWineD3DImpl *This = (IWineD3DImpl *)iface;
192 ULONG ref;
193 TRACE("(%p) : Releasing from %ld\n", This, This->ref);
194 ref = InterlockedDecrement(&This->ref);
195 if (ref == 0) {
196 HeapFree(GetProcessHeap(), 0, This);
199 return ref;
202 /**********************************************************
203 * IWineD3D parts follows
204 **********************************************************/
206 static BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info, Display* display) {
207 const char *GL_Extensions = NULL;
208 const char *GLX_Extensions = NULL;
209 const char *gl_string = NULL;
210 const char *gl_string_cursor = NULL;
211 GLint gl_max;
212 GLfloat gl_float;
213 Bool test = 0;
214 int major, minor;
215 WineD3D_Context *fake_ctx = NULL;
216 BOOL gotContext = FALSE;
217 int i;
219 /* Make sure that we've got a context */
220 if (glXGetCurrentContext() == NULL) {
221 /* TODO: CreateFakeGLContext should really take a display as a parameter */
222 fake_ctx = WineD3D_CreateFakeGLContext();
223 if (NULL != fake_ctx) gotContext = TRUE;
224 } else {
225 gotContext = TRUE;
229 TRACE_(d3d_caps)("(%p, %p)\n", gl_info, display);
231 /* Fill in the GL info retrievable depending on the display */
232 if (NULL != display) {
233 test = glXQueryVersion(display, &major, &minor);
234 gl_info->glx_version = ((major & 0x0000FFFF) << 16) | (minor & 0x0000FFFF);
235 gl_string = glXGetClientString(display, GLX_VENDOR);
236 } else {
237 FIXME("Display must not be NULL, use glXGetCurrentDisplay or getAdapterDisplay()\n");
238 gl_string = (const char *) glGetString(GL_VENDOR);
240 TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
241 if (gl_string != NULL) {
242 /* Fill in the GL vendor */
243 if (strstr(gl_string, "NVIDIA")) {
244 gl_info->gl_vendor = VENDOR_NVIDIA;
245 } else if (strstr(gl_string, "ATI")) {
246 gl_info->gl_vendor = VENDOR_ATI;
247 } else {
248 gl_info->gl_vendor = VENDOR_WINE;
250 } else {
251 gl_info->gl_vendor = VENDOR_WINE;
255 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
257 /* Parse the GL_VERSION field into major and minor information */
258 gl_string = (const char *) glGetString(GL_VERSION);
259 if (gl_string != NULL) {
261 switch (gl_info->gl_vendor) {
262 case VENDOR_NVIDIA:
263 gl_string_cursor = strstr(gl_string, "NVIDIA");
264 gl_string_cursor = strstr(gl_string_cursor, " ");
265 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
266 if (*gl_string_cursor) {
267 char tmp[16];
268 int cursor = 0;
270 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
271 tmp[cursor++] = *gl_string_cursor;
272 ++gl_string_cursor;
274 tmp[cursor] = 0;
275 major = atoi(tmp);
277 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
278 ++gl_string_cursor;
280 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
281 tmp[cursor++] = *gl_string_cursor;
282 ++gl_string_cursor;
284 tmp[cursor] = 0;
285 minor = atoi(tmp);
287 break;
289 case VENDOR_ATI:
290 major = minor = 0;
291 gl_string_cursor = strchr(gl_string, '-');
292 if (gl_string_cursor) {
293 int error = 0;
294 gl_string_cursor++;
296 /* Check if version number is of the form x.y.z */
297 if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
298 error = 1;
299 if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
300 error = 1;
301 if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
302 error = 1;
303 if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
304 error = 1;
306 /* Mark version number as malformed */
307 if (error)
308 gl_string_cursor = 0;
311 if (!gl_string_cursor)
312 WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
313 else {
314 major = *gl_string_cursor - '0';
315 minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
317 break;
319 default:
320 major = 0;
321 minor = 9;
323 gl_info->gl_driver_version = MAKEDWORD_VERSION(major, minor);
324 TRACE_(d3d_caps)("found GL_VERSION (%s)->(0x%08lx)\n", debugstr_a(gl_string), gl_info->gl_driver_version);
326 /* Fill in the renderer information */
327 gl_string = (const char *) glGetString(GL_RENDERER);
328 strcpy(gl_info->gl_renderer, gl_string);
330 switch (gl_info->gl_vendor) {
331 case VENDOR_NVIDIA:
332 if (strstr(gl_info->gl_renderer, "GeForce4 Ti")) {
333 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4600;
334 } else if (strstr(gl_info->gl_renderer, "GeForceFX")) {
335 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5900ULTRA;
336 } else {
337 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4600;
339 break;
341 case VENDOR_ATI:
342 if (strstr(gl_info->gl_renderer, "RADEON 9800 PRO")) {
343 gl_info->gl_card = CARD_ATI_RADEON_9800PRO;
344 } else if (strstr(gl_info->gl_renderer, "RADEON 9700 PRO")) {
345 gl_info->gl_card = CARD_ATI_RADEON_9700PRO;
346 } else {
347 gl_info->gl_card = CARD_ATI_RADEON_8500;
349 break;
351 default:
352 gl_info->gl_card = CARD_WINE;
353 break;
355 } else {
356 FIXME("get version string returned null\n");
359 TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
362 * Initialize openGL extension related variables
363 * with Default values
365 memset(&gl_info->supported, 0, sizeof(gl_info->supported));
366 gl_info->max_textures = 1;
367 gl_info->max_samplers = 1;
368 gl_info->ps_arb_version = PS_VERSION_NOT_SUPPORTED;
369 gl_info->vs_arb_version = VS_VERSION_NOT_SUPPORTED;
370 gl_info->vs_nv_version = VS_VERSION_NOT_SUPPORTED;
371 gl_info->vs_ati_version = VS_VERSION_NOT_SUPPORTED;
373 /* Now work out what GL support this card really has */
374 #define USE_GL_FUNC(type, pfn) gl_info->pfn = NULL;
375 GL_EXT_FUNCS_GEN;
376 #undef USE_GL_FUNC
378 /* Retrieve opengl defaults */
379 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
380 gl_info->max_clipplanes = min(D3DMAXUSERCLIPPLANES, gl_max);
381 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
383 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
384 gl_info->max_lights = gl_max;
385 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
387 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
388 gl_info->max_texture_size = gl_max;
389 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
391 glGetFloatv(GL_POINT_SIZE_RANGE, &gl_float);
392 gl_info->max_pointsize = gl_float;
393 TRACE_(d3d_caps)("Maximum point size support - max texture size=%f\n", gl_float);
395 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
396 GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
397 TRACE_(d3d_caps)("GL_Extensions reported:\n");
399 if (NULL == GL_Extensions) {
400 ERR(" GL_Extensions returns NULL\n");
401 } else {
402 while (*GL_Extensions != 0x00) {
403 const char *Start = GL_Extensions;
404 char ThisExtn[256];
406 memset(ThisExtn, 0x00, sizeof(ThisExtn));
407 while (*GL_Extensions != ' ' && *GL_Extensions != 0x00) {
408 GL_Extensions++;
410 memcpy(ThisExtn, Start, (GL_Extensions - Start));
411 TRACE_(d3d_caps)("- %s\n", ThisExtn);
414 * ARB
416 if (strcmp(ThisExtn, "GL_ARB_fragment_program") == 0) {
417 gl_info->ps_arb_version = PS_VERSION_11;
418 TRACE_(d3d_caps)(" FOUND: ARB Pixel Shader support - version=%02x\n", gl_info->ps_arb_version);
419 gl_info->supported[ARB_FRAGMENT_PROGRAM] = TRUE;
420 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &gl_max);
421 TRACE_(d3d_caps)(" FOUND: ARB Pixel Shader support - GL_MAX_TEXTURE_IMAGE_UNITS_ARB=%u\n", gl_max);
422 gl_info->max_samplers = min(MAX_SAMPLERS, gl_max);
423 } else if (strcmp(ThisExtn, "GL_ARB_multisample") == 0) {
424 TRACE_(d3d_caps)(" FOUND: ARB Multisample support\n");
425 gl_info->supported[ARB_MULTISAMPLE] = TRUE;
426 } else if (strcmp(ThisExtn, "GL_ARB_multitexture") == 0) {
427 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
428 TRACE_(d3d_caps)(" FOUND: ARB Multitexture support - GL_MAX_TEXTURE_UNITS_ARB=%u\n", gl_max);
429 gl_info->supported[ARB_MULTITEXTURE] = TRUE;
430 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
431 gl_info->max_samplers = max(gl_info->max_samplers, gl_max);
432 } else if (strcmp(ThisExtn, "GL_ARB_texture_cube_map") == 0) {
433 TRACE_(d3d_caps)(" FOUND: ARB Texture Cube Map support\n");
434 gl_info->supported[ARB_TEXTURE_CUBE_MAP] = TRUE;
435 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
436 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
437 } else if (strcmp(ThisExtn, "GL_ARB_texture_compression") == 0) {
438 TRACE_(d3d_caps)(" FOUND: ARB Texture Compression support\n");
439 gl_info->supported[ARB_TEXTURE_COMPRESSION] = TRUE;
440 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_add") == 0) {
441 TRACE_(d3d_caps)(" FOUND: ARB Texture Env Add support\n");
442 gl_info->supported[ARB_TEXTURE_ENV_ADD] = TRUE;
443 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_combine") == 0) {
444 TRACE_(d3d_caps)(" FOUND: ARB Texture Env combine support\n");
445 gl_info->supported[ARB_TEXTURE_ENV_COMBINE] = TRUE;
446 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_dot3") == 0) {
447 TRACE_(d3d_caps)(" FOUND: ARB Dot3 support\n");
448 gl_info->supported[ARB_TEXTURE_ENV_DOT3] = TRUE;
449 } else if (strcmp(ThisExtn, "GL_ARB_texture_border_clamp") == 0) {
450 TRACE_(d3d_caps)(" FOUND: ARB Texture border clamp support\n");
451 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] = TRUE;
452 } else if (strcmp(ThisExtn, "GL_ARB_texture_mirrored_repeat") == 0) {
453 TRACE_(d3d_caps)(" FOUND: ARB Texture mirrored repeat support\n");
454 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] = TRUE;
455 } else if (strcmp(ThisExtn, "GLX_ARB_multisample") == 0) {
456 TRACE_(d3d_caps)(" FOUND: ARB multisample support\n");
457 gl_info->supported[ARB_MULTISAMPLE] = TRUE;
458 } else if (strcmp(ThisExtn, "GL_ARB_point_sprite") == 0) {
459 TRACE_(d3d_caps)(" FOUND: ARB point sprint support\n");
460 gl_info->supported[ARB_POINT_SPRITE] = TRUE;
461 } else if (strstr(ThisExtn, "GL_ARB_vertex_program")) {
462 gl_info->vs_arb_version = VS_VERSION_11;
463 TRACE_(d3d_caps)(" FOUND: ARB Vertex Shader support - version=%02x\n", gl_info->vs_arb_version);
464 gl_info->supported[ARB_VERTEX_PROGRAM] = TRUE;
465 } else if (strcmp(ThisExtn, "GL_ARB_vertex_blend") == 0) {
466 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
467 TRACE_(d3d_caps)(" FOUND: ARB Vertex Blend support GL_MAX_VERTEX_UNITS_ARB %d\n", gl_max);
468 gl_info->max_blends = gl_max;
469 gl_info->supported[ARB_VERTEX_BLEND] = TRUE;
470 } else if (strcmp(ThisExtn, "GL_ARB_vertex_buffer_object") == 0) {
471 TRACE_(d3d_caps)(" FOUND: ARB Vertex Buffer support\n");
472 gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] = TRUE;
473 } else if (strcmp(ThisExtn, "GL_ARB_occlusion_query") == 0) {
474 TRACE_(d3d_caps)(" FOUND: ARB Occlusion Query support\n");
475 gl_info->supported[ARB_OCCLUSION_QUERY] = TRUE;
477 * EXT
479 } else if (strcmp(ThisExtn, "GL_EXT_fog_coord") == 0) {
480 TRACE_(d3d_caps)(" FOUND: EXT Fog coord support\n");
481 gl_info->supported[EXT_FOG_COORD] = TRUE;
482 } else if (strcmp(ThisExtn, "GL_EXT_paletted_texture") == 0) { /* handle paletted texture extensions */
483 TRACE_(d3d_caps)(" FOUND: EXT Paletted texture support\n");
484 gl_info->supported[EXT_PALETTED_TEXTURE] = TRUE;
485 } else if (strcmp(ThisExtn, "GL_EXT_point_parameters") == 0) {
486 TRACE_(d3d_caps)(" FOUND: EXT Point parameters support\n");
487 gl_info->supported[EXT_POINT_PARAMETERS] = TRUE;
488 } else if (strcmp(ThisExtn, "GL_EXT_secondary_color") == 0) {
489 TRACE_(d3d_caps)(" FOUND: EXT Secondary coord support\n");
490 gl_info->supported[EXT_SECONDARY_COLOR] = TRUE;
491 } else if (strcmp(ThisExtn, "GL_EXT_stencil_wrap") == 0) {
492 TRACE_(d3d_caps)(" FOUND: EXT Stencil wrap support\n");
493 gl_info->supported[EXT_STENCIL_WRAP] = TRUE;
494 } else if (strcmp(ThisExtn, "GL_EXT_texture_compression_s3tc") == 0) {
495 TRACE_(d3d_caps)(" FOUND: EXT Texture S3TC compression support\n");
496 gl_info->supported[EXT_TEXTURE_COMPRESSION_S3TC] = TRUE;
497 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_add") == 0) {
498 TRACE_(d3d_caps)(" FOUND: EXT Texture Env Add support\n");
499 gl_info->supported[EXT_TEXTURE_ENV_ADD] = TRUE;
500 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_combine") == 0) {
501 TRACE_(d3d_caps)(" FOUND: EXT Texture Env combine support\n");
502 gl_info->supported[EXT_TEXTURE_ENV_COMBINE] = TRUE;
503 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_dot3") == 0) {
504 TRACE_(d3d_caps)(" FOUND: EXT Dot3 support\n");
505 gl_info->supported[EXT_TEXTURE_ENV_DOT3] = TRUE;
506 } else if (strcmp(ThisExtn, "GL_EXT_texture_filter_anisotropic") == 0) {
507 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] = TRUE;
508 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
509 TRACE_(d3d_caps)(" FOUND: EXT Texture Anisotropic filter support. GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT %d\n", gl_max);
510 gl_info->max_anisotropy = gl_max;
511 } else if (strcmp(ThisExtn, "GL_EXT_texture_lod") == 0) {
512 TRACE_(d3d_caps)(" FOUND: EXT Texture LOD support\n");
513 gl_info->supported[EXT_TEXTURE_LOD] = TRUE;
514 } else if (strcmp(ThisExtn, "GL_EXT_texture_lod_bias") == 0) {
515 TRACE_(d3d_caps)(" FOUND: EXT Texture LOD bias support\n");
516 gl_info->supported[EXT_TEXTURE_LOD_BIAS] = TRUE;
517 } else if (strcmp(ThisExtn, "GL_EXT_vertex_weighting") == 0) {
518 TRACE_(d3d_caps)(" FOUND: EXT Vertex weighting support\n");
519 gl_info->supported[EXT_VERTEX_WEIGHTING] = TRUE;
522 * NVIDIA
524 } else if (strstr(ThisExtn, "GL_NV_fog_distance")) {
525 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Fog Distance support\n");
526 gl_info->supported[NV_FOG_DISTANCE] = TRUE;
527 } else if (strstr(ThisExtn, "GL_NV_fragment_program")) {
528 gl_info->ps_nv_version = PS_VERSION_11;
529 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Pixel Shader support - version=%02x\n", gl_info->ps_nv_version);
530 } else if (strcmp(ThisExtn, "GL_NV_register_combiners") == 0) {
531 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Register combiners (1) support\n");
532 gl_info->supported[NV_REGISTER_COMBINERS] = TRUE;
533 } else if (strcmp(ThisExtn, "GL_NV_register_combiners2") == 0) {
534 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Register combiners (2) support\n");
535 gl_info->supported[NV_REGISTER_COMBINERS2] = TRUE;
536 } else if (strcmp(ThisExtn, "GL_NV_texgen_reflection") == 0) {
537 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Gen Reflection support\n");
538 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
539 } else if (strcmp(ThisExtn, "GL_NV_texture_env_combine4") == 0) {
540 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Env combine (4) support\n");
541 gl_info->supported[NV_TEXTURE_ENV_COMBINE4] = TRUE;
542 } else if (strcmp(ThisExtn, "GL_NV_texture_shader") == 0) {
543 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (1) support\n");
544 gl_info->supported[NV_TEXTURE_SHADER] = TRUE;
545 } else if (strcmp(ThisExtn, "GL_NV_texture_shader2") == 0) {
546 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (2) support\n");
547 gl_info->supported[NV_TEXTURE_SHADER2] = TRUE;
548 } else if (strcmp(ThisExtn, "GL_NV_texture_shader3") == 0) {
549 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (3) support\n");
550 gl_info->supported[NV_TEXTURE_SHADER3] = TRUE;
551 } else if (strcmp(ThisExtn, "GL_NV_occlusion_query") == 0) {
552 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Occlusion Query (3) support\n");
553 gl_info->supported[NV_OCCLUSION_QUERY] = TRUE;
554 } else if (strstr(ThisExtn, "GL_NV_vertex_program")) {
555 gl_info->vs_nv_version = max(gl_info->vs_nv_version, (0 == strcmp(ThisExtn, "GL_NV_vertex_program1_1")) ? VS_VERSION_11 : VS_VERSION_10);
556 gl_info->vs_nv_version = max(gl_info->vs_nv_version, (0 == strcmp(ThisExtn, "GL_NV_vertex_program2")) ? VS_VERSION_20 : VS_VERSION_10);
557 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Vertex Shader support - version=%02x\n", gl_info->vs_nv_version);
558 gl_info->supported[NV_VERTEX_PROGRAM] = TRUE;
561 * ATI
563 /** TODO */
564 } else if (strcmp(ThisExtn, "GL_ATI_texture_env_combine3") == 0) {
565 TRACE_(d3d_caps)(" FOUND: ATI Texture Env combine (3) support\n");
566 gl_info->supported[ATI_TEXTURE_ENV_COMBINE3] = TRUE;
567 } else if (strcmp(ThisExtn, "GL_ATI_texture_mirror_once") == 0) {
568 TRACE_(d3d_caps)(" FOUND: ATI Texture Mirror Once support\n");
569 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] = TRUE;
570 } else if (strcmp(ThisExtn, "GL_EXT_vertex_shader") == 0) {
571 gl_info->vs_ati_version = VS_VERSION_11;
572 TRACE_(d3d_caps)(" FOUND: ATI (EXT) Vertex Shader support - version=%02x\n", gl_info->vs_ati_version);
573 gl_info->supported[EXT_VERTEX_SHADER] = TRUE;
577 if (*GL_Extensions == ' ') GL_Extensions++;
581 /* Load all the lookup tables
582 TODO: It may be a good idea to make minLookup and maxLookup const and populate them in wined3d_private.h where they are declared */
583 minLookup[WINELOOKUP_WARPPARAM] = D3DTADDRESS_WRAP;
584 maxLookup[WINELOOKUP_WARPPARAM] = D3DTADDRESS_MIRRORONCE;
586 minLookup[WINELOOKUP_MAGFILTER] = D3DTEXF_NONE;
587 maxLookup[WINELOOKUP_MAGFILTER] = D3DTEXF_ANISOTROPIC;
590 for (i = 0; i < MAX_LOOKUPS; i++) {
591 stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
594 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
595 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
596 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
597 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
598 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
599 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
600 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
601 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
602 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
603 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
605 stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_NONE - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
606 stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_POINT - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
607 stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_LINEAR - minLookup[WINELOOKUP_MAGFILTER]] = GL_LINEAR;
608 stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_ANISOTROPIC - minLookup[WINELOOKUP_MAGFILTER]] =
609 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR : GL_NEAREST;
612 minMipLookup[D3DTEXF_NONE][D3DTEXF_NONE] = GL_LINEAR;
613 minMipLookup[D3DTEXF_NONE][D3DTEXF_POINT] = GL_LINEAR;
614 minMipLookup[D3DTEXF_NONE][D3DTEXF_LINEAR] = GL_LINEAR;
615 minMipLookup[D3DTEXF_POINT][D3DTEXF_NONE] = GL_NEAREST;
616 minMipLookup[D3DTEXF_POINT][D3DTEXF_POINT] = GL_NEAREST_MIPMAP_NEAREST;
617 minMipLookup[D3DTEXF_POINT][D3DTEXF_LINEAR] = GL_NEAREST_MIPMAP_LINEAR;
618 minMipLookup[D3DTEXF_LINEAR][D3DTEXF_NONE] = GL_LINEAR;
619 minMipLookup[D3DTEXF_LINEAR][D3DTEXF_POINT] = GL_LINEAR_MIPMAP_NEAREST;
620 minMipLookup[D3DTEXF_LINEAR][D3DTEXF_LINEAR] = GL_LINEAR_MIPMAP_LINEAR;
621 minMipLookup[D3DTEXF_ANISOTROPIC][D3DTEXF_NONE] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ?
622 GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
623 minMipLookup[D3DTEXF_ANISOTROPIC][D3DTEXF_POINT] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR;
624 minMipLookup[D3DTEXF_ANISOTROPIC][D3DTEXF_LINEAR] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
626 /* TODO: config lookups */
629 #define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) glXGetProcAddressARB( (const GLubyte *) #pfn);
630 GL_EXT_FUNCS_GEN;
631 #undef USE_GL_FUNC
633 if (display != NULL) {
634 GLX_Extensions = glXQueryExtensionsString(display, DefaultScreen(display));
635 TRACE_(d3d_caps)("GLX_Extensions reported:\n");
637 if (NULL == GLX_Extensions) {
638 ERR(" GLX_Extensions returns NULL\n");
639 } else {
640 while (*GLX_Extensions != 0x00) {
641 const char *Start = GLX_Extensions;
642 char ThisExtn[256];
644 memset(ThisExtn, 0x00, sizeof(ThisExtn));
645 while (*GLX_Extensions != ' ' && *GLX_Extensions != 0x00) {
646 GLX_Extensions++;
648 memcpy(ThisExtn, Start, (GLX_Extensions - Start));
649 TRACE_(d3d_caps)("- %s\n", ThisExtn);
650 if (*GLX_Extensions == ' ') GLX_Extensions++;
655 #define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) glXGetProcAddressARB( (const GLubyte *) #pfn);
656 GLX_EXT_FUNCS_GEN;
657 #undef USE_GL_FUNC
659 /* If we created a dummy context, throw it away */
660 if (NULL != fake_ctx) WineD3D_ReleaseFakeGLContext(fake_ctx);
662 /* Only save the values obtained when a display is provided */
663 if (fake_ctx == NULL) {
664 return TRUE;
665 } else {
666 return FALSE;
670 /**********************************************************
671 * IWineD3D implementation follows
672 **********************************************************/
674 UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
675 IWineD3DImpl *This = (IWineD3DImpl *)iface;
677 /* FIXME: Set to one for now to imply the display */
678 TRACE_(d3d_caps)("(%p): Mostly stub, only returns primary display\n", This);
679 return 1;
682 HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
683 IWineD3DImpl *This = (IWineD3DImpl *)iface;
684 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
685 return D3D_OK;
688 HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
689 IWineD3DImpl *This = (IWineD3DImpl *)iface;
690 FIXME_(d3d_caps)("(%p)->(Adptr:%d)\n", This, Adapter);
691 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
692 return NULL;
694 return D3D_OK;
697 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
698 of the same bpp but different resolutions */
700 /* Note: dx9 supplies a format. Calls from d3d8 supply D3DFMT_UNKNOWN */
701 UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
702 IWineD3DImpl *This = (IWineD3DImpl *)iface;
703 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
705 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
706 return 0;
709 if (Adapter == 0) { /* Display */
710 int i = 0;
711 int j = 0;
712 #if !defined( DEBUG_SINGLE_MODE )
713 DEVMODEW DevModeW;
715 /* Work out the current screen bpp */
716 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
717 int bpp = GetDeviceCaps(hdc, BITSPIXEL);
718 DeleteDC(hdc);
720 while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
721 j++;
722 switch (Format)
724 case D3DFMT_UNKNOWN:
725 i++;
726 break;
727 case D3DFMT_X8R8G8B8:
728 case D3DFMT_A8R8G8B8:
729 if (min(DevModeW.dmBitsPerPel, bpp) == 32) i++;
730 if (min(DevModeW.dmBitsPerPel, bpp) == 24) i++;
731 break;
732 case D3DFMT_X1R5G5B5:
733 case D3DFMT_A1R5G5B5:
734 case D3DFMT_R5G6B5:
735 if (min(DevModeW.dmBitsPerPel, bpp) == 16) i++;
736 break;
737 default:
738 /* Skip other modes as they do not match requested format */
739 break;
742 #else
743 i = 1;
744 j = 1;
745 #endif
746 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
747 return i;
748 } else {
749 FIXME_(d3d_caps)("Adapter not primary display\n");
751 return 0;
754 /* Note: dx9 supplies a format. Calls from d3d8 supply D3DFMT_UNKNOWN */
755 HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) {
756 IWineD3DImpl *This = (IWineD3DImpl *)iface;
757 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
759 /* Validate the parameters as much as possible */
760 if (NULL == pMode ||
761 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
762 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
763 return D3DERR_INVALIDCALL;
766 if (Adapter == 0) { /* Display */
767 #if !defined( DEBUG_SINGLE_MODE )
768 DEVMODEW DevModeW;
769 int ModeIdx = 0;
771 /* Work out the current screen bpp */
772 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
773 int bpp = GetDeviceCaps(hdc, BITSPIXEL);
774 DeleteDC(hdc);
776 /* If we are filtering to a specific format, then need to skip all unrelated
777 modes, but if mode is irrelevant, then we can use the index directly */
778 if (Format == D3DFMT_UNKNOWN)
780 ModeIdx = Mode;
781 } else {
782 int i = 0;
783 int j = 0;
784 DEVMODEW DevModeWtmp;
787 while (i<(Mode) && EnumDisplaySettingsExW(NULL, j, &DevModeWtmp, 0)) {
788 j++;
789 switch (Format)
791 case D3DFMT_UNKNOWN:
792 i++;
793 break;
794 case D3DFMT_X8R8G8B8:
795 case D3DFMT_A8R8G8B8:
796 if (min(DevModeWtmp.dmBitsPerPel, bpp) == 32) i++;
797 if (min(DevModeWtmp.dmBitsPerPel, bpp) == 24) i++;
798 break;
799 case D3DFMT_X1R5G5B5:
800 case D3DFMT_A1R5G5B5:
801 case D3DFMT_R5G6B5:
802 if (min(DevModeWtmp.dmBitsPerPel, bpp) == 16) i++;
803 break;
804 default:
805 /* Skip other modes as they do not match requested format */
806 break;
809 ModeIdx = j;
812 /* Now get the display mode via the calculated index */
813 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0))
815 pMode->Width = DevModeW.dmPelsWidth;
816 pMode->Height = DevModeW.dmPelsHeight;
817 bpp = min(DevModeW.dmBitsPerPel, bpp);
818 pMode->RefreshRate = D3DADAPTER_DEFAULT;
819 if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
821 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
824 if (Format == D3DFMT_UNKNOWN)
826 switch (bpp) {
827 case 8: pMode->Format = D3DFMT_R3G3B2; break;
828 case 16: pMode->Format = D3DFMT_R5G6B5; break;
829 case 24: /* Robots needs 24 and 32 bit as X8R8G8B8 to start */
830 case 32: pMode->Format = D3DFMT_X8R8G8B8; break;
831 default: pMode->Format = D3DFMT_UNKNOWN;
833 } else {
834 pMode->Format = Format;
837 else
839 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
840 return D3DERR_INVALIDCALL;
843 #else
844 /* Return one setting of the format requested */
845 if (Mode > 0) return D3DERR_INVALIDCALL;
846 pMode->Width = 800;
847 pMode->Height = 600;
848 pMode->RefreshRate = D3DADAPTER_DEFAULT;
849 pMode->Format = (Format == D3DFMT_UNKNOWN) ? D3DFMT_A8R8G8B8 : Format;
850 bpp = 32;
851 #endif
852 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
853 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format), bpp);
855 } else {
856 FIXME_(d3d_caps)("Adapter not primary display\n");
859 return D3D_OK;
862 HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
863 IWineD3DImpl *This = (IWineD3DImpl *)iface;
864 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
866 if (NULL == pMode ||
867 Adapter >= IWineD3D_GetAdapterCount(iface)) {
868 return D3DERR_INVALIDCALL;
871 if (Adapter == 0) { /* Display */
872 int bpp = 0;
873 DEVMODEW DevModeW;
875 EnumDisplaySettingsExW(NULL, (DWORD)-1, &DevModeW, 0);
876 pMode->Width = DevModeW.dmPelsWidth;
877 pMode->Height = DevModeW.dmPelsHeight;
878 bpp = DevModeW.dmBitsPerPel;
879 pMode->RefreshRate = D3DADAPTER_DEFAULT;
880 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
882 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
885 switch (bpp) {
886 case 8: pMode->Format = D3DFMT_R3G3B2; break;
887 case 16: pMode->Format = D3DFMT_R5G6B5; break;
888 case 24: pMode->Format = D3DFMT_X8R8G8B8; break; /* Robots needs 24bit to be X8R8G8B8 */
889 case 32: pMode->Format = D3DFMT_A8R8G8B8; break;
890 default: pMode->Format = D3DFMT_UNKNOWN;
893 } else {
894 FIXME_(d3d_caps)("Adapter not primary display\n");
897 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
898 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
899 return D3D_OK;
902 static Display * WINAPI IWineD3DImpl_GetAdapterDisplay(IWineD3D *iface, UINT Adapter) {
903 Display *display;
904 HDC device_context;
905 /* only works with one adapter at the moment... */
907 /* Get the display */
908 device_context = GetDC(0);
909 display = get_display(device_context);
910 ReleaseDC(0, device_context);
911 return display;
914 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
915 and fields being inserted in the middle, a new structure is used in place */
916 HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
917 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
918 IWineD3DImpl *This = (IWineD3DImpl *)iface;
920 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %lx, pId=%p)\n", This, Adapter, Flags, pIdentifier);
922 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
923 return D3DERR_INVALIDCALL;
926 if (Adapter == 0) { /* Display - only device supported for now */
928 BOOL isGLInfoValid = This->isGLInfoValid;
930 /* FillGLCaps updates gl_info, but we only want to store and
931 reuse the values once we have a context which is valid. Values from
932 a temporary context may differ from the final ones */
933 if (isGLInfoValid == FALSE) {
934 /* If we don't know the device settings, go query them now */
935 isGLInfoValid = IWineD3DImpl_FillGLCaps(&This->gl_info, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
938 /* If it worked, return the information requested */
939 if (isGLInfoValid) {
940 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
941 strcpy(pIdentifier->Driver, "Display");
942 strcpy(pIdentifier->Description, "Direct3D HAL");
944 /* Note dx8 doesn't supply a DeviceName */
945 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
946 pIdentifier->DriverVersion->u.HighPart = 0xa;
947 pIdentifier->DriverVersion->u.LowPart = This->gl_info.gl_driver_version;
948 *(pIdentifier->VendorId) = This->gl_info.gl_vendor;
949 *(pIdentifier->DeviceId) = This->gl_info.gl_card;
950 *(pIdentifier->SubSysId) = 0;
951 *(pIdentifier->Revision) = 0;
953 } else {
955 /* If it failed, return dummy values from an NVidia driver */
956 WARN_(d3d_caps)("Cannot get GLCaps for device/Vendor Name and Version detection using FillGLCaps, currently using NVIDIA identifiers\n");
957 strcpy(pIdentifier->Driver, "Display");
958 strcpy(pIdentifier->Description, "Direct3D HAL");
959 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
960 pIdentifier->DriverVersion->u.HighPart = 0xa;
961 pIdentifier->DriverVersion->u.LowPart = MAKEDWORD_VERSION(53, 96); /* last Linux Nvidia drivers */
962 *(pIdentifier->VendorId) = VENDOR_NVIDIA;
963 *(pIdentifier->DeviceId) = CARD_NVIDIA_GEFORCE4_TI4600;
964 *(pIdentifier->SubSysId) = 0;
965 *(pIdentifier->Revision) = 0;
968 /*FIXME: memcpy(&pIdentifier->DeviceIdentifier, ??, sizeof(??GUID)); */
969 if (Flags & D3DENUM_NO_WHQL_LEVEL) {
970 *(pIdentifier->WHQLLevel) = 0;
971 } else {
972 *(pIdentifier->WHQLLevel) = 1;
975 } else {
976 FIXME_(d3d_caps)("Adapter not primary display\n");
979 return D3D_OK;
982 static BOOL IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(WineD3D_Context* ctx, GLXFBConfig cfgs, WINED3DFORMAT Format) {
983 #if 0 /* This code performs a strict test between the format and the current X11 buffer depth, which may give the best performance */
984 int gl_test;
985 int rb, gb, bb, ab, type, buf_sz;
987 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_RED_SIZE, &rb);
988 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_GREEN_SIZE, &gb);
989 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_BLUE_SIZE, &bb);
990 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_ALPHA_SIZE, &ab);
991 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_RENDER_TYPE, &type);
992 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_BUFFER_SIZE, &buf_sz);
994 switch (Format) {
995 case WINED3DFMT_X8R8G8B8:
996 case WINED3DFMT_R8G8B8:
997 if (8 == rb && 8 == gb && 8 == bb) return TRUE;
998 break;
999 case WINED3DFMT_A8R8G8B8:
1000 if (8 == rb && 8 == gb && 8 == bb && 8 == ab) return TRUE;
1001 break;
1002 case WINED3DFMT_A2R10G10B10:
1003 if (10 == rb && 10 == gb && 10 == bb && 2 == ab) return TRUE;
1004 break;
1005 case WINED3DFMT_X1R5G5B5:
1006 if (5 == rb && 5 == gb && 5 == bb) return TRUE;
1007 break;
1008 case WINED3DFMT_A1R5G5B5:
1009 if (5 == rb && 5 == gb && 5 == bb && 1 == ab) return TRUE;
1010 break;
1011 case WINED3DFMT_R5G6B5:
1012 if (5 == rb && 6 == gb && 5 == bb) return TRUE;
1013 break;
1014 case WINED3DFMT_R3G3B2:
1015 if (3 == rb && 3 == gb && 2 == bb) return TRUE;
1016 break;
1017 case WINED3DFMT_A8P8:
1018 if (type & GLX_COLOR_INDEX_BIT && 8 == buf_sz && 8 == ab) return TRUE;
1019 break;
1020 case WINED3DFMT_P8:
1021 if (type & GLX_COLOR_INDEX_BIT && 8 == buf_sz) return TRUE;
1022 break;
1023 default:
1024 ERR("unsupported format %s\n", debug_d3dformat(Format));
1025 break;
1027 return FALSE;
1028 #else /* Most of the time performance is less of an issue than compatability, this code allows for most common opengl/d3d formats */
1029 switch (Format) {
1030 case WINED3DFMT_X8R8G8B8:
1031 case WINED3DFMT_R8G8B8:
1032 case WINED3DFMT_A8R8G8B8:
1033 case WINED3DFMT_A2R10G10B10:
1034 case WINED3DFMT_X1R5G5B5:
1035 case WINED3DFMT_A1R5G5B5:
1036 case WINED3DFMT_R5G6B5:
1037 case WINED3DFMT_R3G3B2:
1038 case WINED3DFMT_A8P8:
1039 case WINED3DFMT_P8:
1040 return TRUE;
1041 default:
1042 ERR("unsupported format %s\n", debug_d3dformat(Format));
1043 break;
1045 return FALSE;
1046 #endif
1049 static BOOL IWineD3DImpl_IsGLXFBConfigCompatibleWithDepthFmt(WineD3D_Context* ctx, GLXFBConfig cfgs, WINED3DFORMAT Format) {
1050 #if 0/* This code performs a strict test between the format and the current X11 buffer depth, which may give the best performance */
1051 int gl_test;
1052 int db, sb;
1054 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_DEPTH_SIZE, &db);
1055 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_STENCIL_SIZE, &sb);
1057 switch (Format) {
1058 case WINED3DFMT_D16:
1059 case WINED3DFMT_D16_LOCKABLE:
1060 if (16 == db) return TRUE;
1061 break;
1062 case WINED3DFMT_D32:
1063 if (32 == db) return TRUE;
1064 break;
1065 case WINED3DFMT_D15S1:
1066 if (15 == db) return TRUE;
1067 break;
1068 case WINED3DFMT_D24S8:
1069 if (24 == db && 8 == sb) return TRUE;
1070 break;
1071 case WINED3DFMT_D24FS8:
1072 if (24 == db && 8 == sb) return TRUE;
1073 break;
1074 case WINED3DFMT_D24X8:
1075 if (24 == db) return TRUE;
1076 break;
1077 case WINED3DFMT_D24X4S4:
1078 if (24 == db && 4 == sb) return TRUE;
1079 break;
1080 case WINED3DFMT_D32F_LOCKABLE:
1081 if (32 == db) return TRUE;
1082 break;
1083 default:
1084 ERR("unsupported format %s\n", debug_d3dformat(Format));
1085 break;
1087 return FALSE;
1088 #else /* Most of the time performance is less of an issue than compatability, this code allows for most common opengl/d3d formats */
1089 switch (Format) {
1090 case WINED3DFMT_D16:
1091 case WINED3DFMT_D16_LOCKABLE:
1092 case WINED3DFMT_D32:
1093 case WINED3DFMT_D15S1:
1094 case WINED3DFMT_D24S8:
1095 case WINED3DFMT_D24FS8:
1096 case WINED3DFMT_D24X8:
1097 case WINED3DFMT_D24X4S4:
1098 case WINED3DFMT_D32F_LOCKABLE:
1099 return TRUE;
1100 default:
1101 ERR("unsupported format %s\n", debug_d3dformat(Format));
1102 break;
1104 return FALSE;
1105 #endif
1108 HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1109 WINED3DFORMAT AdapterFormat,
1110 WINED3DFORMAT RenderTargetFormat,
1111 WINED3DFORMAT DepthStencilFormat) {
1112 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1113 HRESULT hr = D3DERR_NOTAVAILABLE;
1114 WineD3D_Context* ctx = NULL;
1115 GLXFBConfig* cfgs = NULL;
1116 int nCfgs = 0;
1117 int it;
1119 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
1120 This, Adapter,
1121 DeviceType, debug_d3ddevicetype(DeviceType),
1122 AdapterFormat, debug_d3dformat(AdapterFormat),
1123 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
1124 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
1126 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1127 TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning D3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
1128 return D3DERR_INVALIDCALL;
1130 /* TODO: use the real context if it's available */
1131 ctx = WineD3D_CreateFakeGLContext();
1132 if(NULL != ctx) {
1133 cfgs = glXGetFBConfigs(ctx->display, DefaultScreen(ctx->display), &nCfgs);
1134 } else {
1135 TRACE_(d3d_caps)("(%p) : Unable to create a fake context at this time (there may already be an active context)\n", This);
1138 if (NULL != cfgs) {
1139 for (it = 0; it < nCfgs; ++it) {
1140 if (IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(ctx, cfgs[it], RenderTargetFormat)) {
1141 if (IWineD3DImpl_IsGLXFBConfigCompatibleWithDepthFmt(ctx, cfgs[it], DepthStencilFormat)) {
1142 hr = D3D_OK;
1143 break ;
1147 XFree(cfgs);
1148 cfgs = NULL;
1149 } else {
1150 /* If there's a corrent context then we cannot create a fake one so pass everything */
1151 hr = D3D_OK;
1154 if (ctx != NULL)
1155 WineD3D_ReleaseFakeGLContext(ctx);
1157 if (hr != D3D_OK)
1158 TRACE_(d3d_caps)("Failed to match stencil format to device\b");
1160 TRACE_(d3d_caps)("(%p) : Returning %lx\n", This, hr);
1161 return hr;
1164 HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1165 WINED3DFORMAT SurfaceFormat,
1166 BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
1168 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1169 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
1170 This,
1171 Adapter,
1172 DeviceType, debug_d3ddevicetype(DeviceType),
1173 SurfaceFormat, debug_d3dformat(SurfaceFormat),
1174 Windowed,
1175 MultiSampleType,
1176 pQualityLevels);
1178 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1179 return D3DERR_INVALIDCALL;
1182 if (pQualityLevels != NULL) {
1183 static int s_single_shot = 0;
1184 if (!s_single_shot) {
1185 FIXME("Quality levels unsupported at present\n");
1186 s_single_shot = 1;
1188 *pQualityLevels = 1; /* Guess at a value! */
1191 if (D3DMULTISAMPLE_NONE == MultiSampleType) return D3D_OK;
1192 return D3DERR_NOTAVAILABLE;
1195 HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, D3DDEVTYPE CheckType,
1196 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
1198 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1199 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
1200 This,
1201 Adapter,
1202 CheckType, debug_d3ddevicetype(CheckType),
1203 DisplayFormat, debug_d3dformat(DisplayFormat),
1204 BackBufferFormat, debug_d3dformat(BackBufferFormat),
1205 Windowed);
1207 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1208 return D3DERR_INVALIDCALL;
1212 GLXFBConfig* cfgs = NULL;
1213 int nCfgs = 0;
1214 int it;
1215 HRESULT hr = D3DERR_NOTAVAILABLE;
1217 WineD3D_Context* ctx = WineD3D_CreateFakeGLContext();
1218 if (NULL != ctx) {
1219 cfgs = glXGetFBConfigs(ctx->display, DefaultScreen(ctx->display), &nCfgs);
1220 for (it = 0; it < nCfgs; ++it) {
1221 if (IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(ctx, cfgs[it], DisplayFormat)) {
1222 hr = D3D_OK;
1223 break ;
1226 XFree(cfgs);
1228 WineD3D_ReleaseFakeGLContext(ctx);
1229 return hr;
1233 return D3DERR_NOTAVAILABLE;
1236 HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1237 WINED3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat) {
1238 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1239 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%lu,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s)) ",
1240 This,
1241 Adapter,
1242 DeviceType, debug_d3ddevicetype(DeviceType),
1243 AdapterFormat, debug_d3dformat(AdapterFormat),
1244 Usage, debug_d3dusage(Usage),
1245 RType, debug_d3dresourcetype(RType),
1246 CheckFormat, debug_d3dformat(CheckFormat));
1248 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1249 return D3DERR_INVALIDCALL;
1252 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1253 switch (CheckFormat) {
1254 case D3DFMT_DXT1:
1255 case D3DFMT_DXT2:
1256 case D3DFMT_DXT3:
1257 case D3DFMT_DXT4:
1258 case D3DFMT_DXT5:
1259 TRACE_(d3d_caps)("[OK]\n");
1260 return D3D_OK;
1261 default:
1262 break; /* Avoid compiler warnings */
1266 switch (CheckFormat) {
1267 /*****
1268 * check supported using GL_SUPPORT
1270 case D3DFMT_DXT1:
1271 case D3DFMT_DXT2:
1272 case D3DFMT_DXT3:
1273 case D3DFMT_DXT4:
1274 case D3DFMT_DXT5:
1276 /*****
1277 * supported
1279 /*case D3DFMT_R5G6B5: */
1280 /*case D3DFMT_X1R5G5B5:*/
1281 /*case D3DFMT_A1R5G5B5: */
1282 /*case D3DFMT_A4R4G4B4:*/
1284 /*****
1285 * unsupported
1288 /* color buffer */
1289 /*case D3DFMT_X8R8G8B8:*/
1290 case D3DFMT_A8R3G3B2:
1292 /* Paletted */
1293 case D3DFMT_P8:
1294 case D3DFMT_A8P8:
1296 /* Luminance */
1297 case D3DFMT_L8:
1298 case D3DFMT_A8L8:
1299 case D3DFMT_A4L4:
1301 /* Bump */
1302 #if 0
1303 case D3DFMT_V8U8:
1304 case D3DFMT_V16U16:
1305 #endif
1306 case D3DFMT_L6V5U5:
1307 case D3DFMT_X8L8V8U8:
1308 case D3DFMT_Q8W8V8U8:
1309 case D3DFMT_W11V11U10:
1311 /****
1312 * currently hard to support
1314 case D3DFMT_UYVY:
1315 case D3DFMT_YUY2:
1317 /* Since we do not support these formats right now, don't pretend to. */
1318 TRACE_(d3d_caps)("[FAILED]\n");
1319 return D3DERR_NOTAVAILABLE;
1320 default:
1321 break;
1324 TRACE_(d3d_caps)("[OK]\n");
1325 return D3D_OK;
1328 HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1329 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
1330 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1332 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))",
1333 This,
1334 Adapter,
1335 DeviceType, debug_d3ddevicetype(DeviceType),
1336 SourceFormat, debug_d3dformat(SourceFormat),
1337 TargetFormat, debug_d3dformat(TargetFormat));
1338 return D3D_OK;
1341 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
1342 subset of a D3DCAPS9 structure. However, it has to come via a void *
1343 as the d3d8 interface cannot import the d3d9 header */
1344 HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
1346 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1348 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
1350 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1351 return D3DERR_INVALIDCALL;
1354 /* If we don't know the device settings, go query them now */
1355 if (This->isGLInfoValid == FALSE) {
1356 /* use the desktop window to fill gl caps */
1357 BOOL rc = IWineD3DImpl_FillGLCaps(&This->gl_info, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
1359 /* We are running off a real context, save the values */
1360 if (rc) This->isGLInfoValid = TRUE;
1364 /* ------------------------------------------------
1365 The following fields apply to both d3d8 and d3d9
1366 ------------------------------------------------ */
1367 *pCaps->DeviceType = (DeviceType == D3DDEVTYPE_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
1368 *pCaps->AdapterOrdinal = Adapter;
1370 *pCaps->Caps = 0;
1371 *pCaps->Caps2 = D3DCAPS2_CANRENDERWINDOWED;
1372 *pCaps->Caps3 = D3DDEVCAPS_HWTRANSFORMANDLIGHT;
1373 *pCaps->PresentationIntervals = D3DPRESENT_INTERVAL_IMMEDIATE;
1375 *pCaps->CursorCaps = 0;
1378 *pCaps->DevCaps = D3DDEVCAPS_DRAWPRIMTLVERTEX |
1379 D3DDEVCAPS_HWTRANSFORMANDLIGHT |
1380 D3DDEVCAPS_PUREDEVICE |
1381 D3DDEVCAPS_HWRASTERIZATION;
1384 *pCaps->PrimitiveMiscCaps = D3DPMISCCAPS_CULLCCW |
1385 D3DPMISCCAPS_CULLCW |
1386 D3DPMISCCAPS_COLORWRITEENABLE |
1387 D3DPMISCCAPS_CLIPTLVERTS |
1388 D3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
1389 D3DPMISCCAPS_MASKZ;
1390 /*NOT: D3DPMISCCAPS_TSSARGTEMP*/
1392 *pCaps->RasterCaps = D3DPRASTERCAPS_DITHER |
1393 D3DPRASTERCAPS_PAT |
1394 D3DPRASTERCAPS_WFOG |
1395 D3DPRASTERCAPS_ZFOG |
1396 D3DPRASTERCAPS_FOGVERTEX |
1397 D3DPRASTERCAPS_FOGTABLE |
1398 D3DPRASTERCAPS_FOGRANGE;
1400 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
1401 *pCaps->RasterCaps |= D3DPRASTERCAPS_ANISOTROPY |
1402 D3DPRASTERCAPS_ZBIAS |
1403 D3DPRASTERCAPS_MIPMAPLODBIAS;
1405 /* FIXME Add:
1406 D3DPRASTERCAPS_COLORPERSPECTIVE
1407 D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
1408 D3DPRASTERCAPS_ANTIALIASEDGES
1409 D3DPRASTERCAPS_ZBUFFERLESSHSR
1410 D3DPRASTERCAPS_WBUFFER */
1412 *pCaps->ZCmpCaps = D3DPCMPCAPS_ALWAYS |
1413 D3DPCMPCAPS_EQUAL |
1414 D3DPCMPCAPS_GREATER |
1415 D3DPCMPCAPS_GREATEREQUAL |
1416 D3DPCMPCAPS_LESS |
1417 D3DPCMPCAPS_LESSEQUAL |
1418 D3DPCMPCAPS_NEVER |
1419 D3DPCMPCAPS_NOTEQUAL;
1421 *pCaps->SrcBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
1422 *pCaps->DestBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
1423 *pCaps->AlphaCmpCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
1425 *pCaps->ShadeCaps = D3DPSHADECAPS_SPECULARGOURAUDRGB |
1426 D3DPSHADECAPS_COLORGOURAUDRGB;
1428 *pCaps->TextureCaps = D3DPTEXTURECAPS_ALPHA |
1429 D3DPTEXTURECAPS_ALPHAPALETTE |
1430 D3DPTEXTURECAPS_VOLUMEMAP |
1431 D3DPTEXTURECAPS_MIPMAP |
1432 D3DPTEXTURECAPS_PROJECTED |
1433 D3DPTEXTURECAPS_PERSPECTIVE |
1434 D3DPTEXTURECAPS_VOLUMEMAP_POW2 ;
1435 /* TODO: add support for NON-POW2 if avaialble
1438 if (This->dxVersion > 8) {
1439 *pCaps->TextureCaps |= D3DPTEXTURECAPS_NONPOW2CONDITIONAL;
1441 } else { /* NONPOW2 isn't accessible by d3d8 yet */
1442 *pCaps->TextureCaps |= D3DPTEXTURECAPS_POW2;
1445 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
1446 *pCaps->TextureCaps |= D3DPTEXTURECAPS_CUBEMAP |
1447 D3DPTEXTURECAPS_MIPCUBEMAP |
1448 D3DPTEXTURECAPS_CUBEMAP_POW2;
1452 *pCaps->TextureFilterCaps = D3DPTFILTERCAPS_MAGFLINEAR |
1453 D3DPTFILTERCAPS_MAGFPOINT |
1454 D3DPTFILTERCAPS_MINFLINEAR |
1455 D3DPTFILTERCAPS_MINFPOINT |
1456 D3DPTFILTERCAPS_MIPFLINEAR |
1457 D3DPTFILTERCAPS_MIPFPOINT;
1459 *pCaps->CubeTextureFilterCaps = 0;
1460 *pCaps->VolumeTextureFilterCaps = 0;
1462 *pCaps->TextureAddressCaps = D3DPTADDRESSCAPS_BORDER |
1463 D3DPTADDRESSCAPS_CLAMP |
1464 D3DPTADDRESSCAPS_WRAP;
1466 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
1467 *pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_BORDER;
1469 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
1470 *pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRROR;
1472 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
1473 *pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
1476 *pCaps->VolumeTextureAddressCaps = 0;
1478 *pCaps->LineCaps = D3DLINECAPS_TEXTURE |
1479 D3DLINECAPS_ZTEST;
1480 /* FIXME: Add
1481 D3DLINECAPS_BLEND
1482 D3DLINECAPS_ALPHACMP
1483 D3DLINECAPS_FOG */
1485 *pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
1486 *pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
1488 *pCaps->MaxVolumeExtent = 0;
1490 *pCaps->MaxTextureRepeat = 32768;
1491 *pCaps->MaxTextureAspectRatio = 32768;
1492 *pCaps->MaxVertexW = 1.0;
1494 *pCaps->GuardBandLeft = 0;
1495 *pCaps->GuardBandTop = 0;
1496 *pCaps->GuardBandRight = 0;
1497 *pCaps->GuardBandBottom = 0;
1499 *pCaps->ExtentsAdjust = 0;
1501 *pCaps->StencilCaps = D3DSTENCILCAPS_DECRSAT |
1502 D3DSTENCILCAPS_INCRSAT |
1503 D3DSTENCILCAPS_INVERT |
1504 D3DSTENCILCAPS_KEEP |
1505 D3DSTENCILCAPS_REPLACE |
1506 D3DSTENCILCAPS_ZERO;
1507 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
1508 *pCaps->StencilCaps |= D3DSTENCILCAPS_DECR |
1509 D3DSTENCILCAPS_INCR;
1512 *pCaps->FVFCaps = D3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
1514 *pCaps->TextureOpCaps = D3DTEXOPCAPS_ADD |
1515 D3DTEXOPCAPS_ADDSIGNED |
1516 D3DTEXOPCAPS_ADDSIGNED2X |
1517 D3DTEXOPCAPS_MODULATE |
1518 D3DTEXOPCAPS_MODULATE2X |
1519 D3DTEXOPCAPS_MODULATE4X |
1520 D3DTEXOPCAPS_SELECTARG1 |
1521 D3DTEXOPCAPS_SELECTARG2 |
1522 D3DTEXOPCAPS_DISABLE;
1523 #if defined(GL_VERSION_1_3)
1524 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_DOTPRODUCT3 |
1525 D3DTEXOPCAPS_SUBTRACT;
1526 #endif
1527 if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE) ||
1528 GL_SUPPORT(EXT_TEXTURE_ENV_COMBINE) ||
1529 GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1530 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_BLENDDIFFUSEALPHA |
1531 D3DTEXOPCAPS_BLENDTEXTUREALPHA |
1532 D3DTEXOPCAPS_BLENDFACTORALPHA |
1533 D3DTEXOPCAPS_BLENDCURRENTALPHA |
1534 D3DTEXOPCAPS_LERP;
1536 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1537 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_ADDSMOOTH |
1538 D3DTEXOPCAPS_MULTIPLYADD |
1539 D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
1540 D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
1541 D3DTEXOPCAPS_BLENDTEXTUREALPHAPM;
1544 #if 0
1545 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_BUMPENVMAP;
1546 /* FIXME: Add
1547 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
1548 D3DTEXOPCAPS_PREMODULATE */
1549 #endif
1551 *pCaps->MaxTextureBlendStages = GL_LIMITS(textures);
1552 *pCaps->MaxSimultaneousTextures = GL_LIMITS(textures);
1553 *pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
1554 *pCaps->MaxActiveLights = GL_LIMITS(lights);
1558 #if 0 /* TODO: Blends support in drawprim */
1559 *pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
1560 #else
1561 *pCaps->MaxVertexBlendMatrices = 0;
1562 #endif
1563 *pCaps->MaxVertexBlendMatrixIndex = 1;
1565 *pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
1566 *pCaps->MaxPointSize = GL_LIMITS(pointsize);
1569 *pCaps->VertexProcessingCaps = D3DVTXPCAPS_DIRECTIONALLIGHTS |
1570 D3DVTXPCAPS_MATERIALSOURCE7 |
1571 D3DVTXPCAPS_POSITIONALLIGHTS |
1572 D3DVTXPCAPS_LOCALVIEWER |
1573 D3DVTXPCAPS_TEXGEN;
1574 /* FIXME: Add
1575 D3DVTXPCAPS_TWEENING */
1577 *pCaps->MaxPrimitiveCount = 0xFFFFFFFF;
1578 *pCaps->MaxVertexIndex = 0xFFFFFFFF;
1579 *pCaps->MaxStreams = MAX_STREAMS;
1580 *pCaps->MaxStreamStride = 1024;
1582 if (((wined3d_settings.vs_mode == VS_HW) && GL_SUPPORT(ARB_VERTEX_PROGRAM)) || (wined3d_settings.vs_mode == VS_SW) || (DeviceType == D3DDEVTYPE_REF)) {
1583 *pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
1585 if (This->gl_info.gl_vendor == VENDOR_MESA ||
1586 This->gl_info.gl_vendor == VENDOR_WINE) {
1587 *pCaps->MaxVertexShaderConst = 95;
1588 } else {
1589 *pCaps->MaxVertexShaderConst = WINED3D_VSHADER_MAX_CONSTANTS;
1591 } else {
1592 *pCaps->VertexShaderVersion = 0;
1593 *pCaps->MaxVertexShaderConst = 0;
1596 if ((wined3d_settings.ps_mode == PS_HW) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM) && (DeviceType != D3DDEVTYPE_REF)) {
1597 *pCaps->PixelShaderVersion = D3DPS_VERSION(1,4);
1598 *pCaps->PixelShader1xMaxValue = 1.0;
1599 } else {
1600 *pCaps->PixelShaderVersion = 0;
1601 *pCaps->PixelShader1xMaxValue = 0.0;
1603 /* TODO: ARB_FRAGMENT_PROGRAM_100 */
1605 /* ------------------------------------------------
1606 The following fields apply to d3d9 only
1607 ------------------------------------------------ */
1608 if (This->dxVersion > 8) {
1609 GLint max_buffers = 1;
1610 FIXME("Caps support for directx9 is nonexistent at the moment!\n");
1611 *pCaps->DevCaps2 = 0;
1612 /* TODO: D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES */
1613 *pCaps->MaxNpatchTessellationLevel = 0;
1614 *pCaps->MasterAdapterOrdinal = 0;
1615 *pCaps->AdapterOrdinalInGroup = 0;
1616 *pCaps->NumberOfAdaptersInGroup = 1;
1617 *pCaps->DeclTypes = 0;
1618 #if 0 /*FIXME: Simultaneous render targets*/
1619 GL_MAX_DRAW_BUFFERS_ATI 0x00008824
1620 if (GL_SUPPORT(GL_MAX_DRAW_BUFFERS_ATI)) {
1621 ENTER_GL();
1622 glEnable(GL_MAX_DRAW_BUFFERS_ATI);
1623 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ATI, &max_buffers);
1624 glDisable(GL_MAX_DRAW_BUFFERS_ATI);
1625 LEAVE_GL();
1627 #endif
1628 *pCaps->NumSimultaneousRTs = max_buffers;
1629 *pCaps->StretchRectFilterCaps = 0;
1630 /* TODO: add
1631 D3DPTFILTERCAPS_MINFPOINT
1632 D3DPTFILTERCAPS_MAGFPOINT
1633 D3DPTFILTERCAPS_MINFLINEAR
1634 D3DPTFILTERCAPS_MAGFLINEAR
1636 *pCaps->VS20Caps.Caps = 0;
1637 *pCaps->PS20Caps.Caps = 0;
1638 *pCaps->VertexTextureFilterCaps = 0;
1639 *pCaps->MaxVShaderInstructionsExecuted = 0;
1640 *pCaps->MaxPShaderInstructionsExecuted = 0;
1641 *pCaps->MaxVertexShader30InstructionSlots = 0;
1642 *pCaps->MaxPixelShader30InstructionSlots = 0;
1645 return D3D_OK;
1649 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
1650 and fields being inserted in the middle, a new structure is used in place */
1651 HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
1652 DWORD BehaviourFlags, WINED3DPRESENT_PARAMETERS* pPresentationParameters,
1653 IWineD3DDevice** ppReturnedDeviceInterface, IUnknown *parent,
1654 D3DCB_CREATEADDITIONALSWAPCHAIN D3DCB_CreateAdditionalSwapChain) {
1656 IWineD3DDeviceImpl *object = NULL;
1657 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1658 IWineD3DSwapChainImpl *swapchain;
1660 /* Validate the adapter number */
1661 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1662 return D3DERR_INVALIDCALL;
1665 /* Create a WineD3DDevice object */
1666 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
1667 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
1668 TRACE("Created WineD3DDevice object @ %p \n", object);
1669 if (NULL == object) {
1670 return D3DERR_OUTOFVIDEOMEMORY;
1673 /* Set up initial COM information */
1674 object->lpVtbl = &IWineD3DDevice_Vtbl;
1675 object->ref = 1;
1676 object->wineD3D = iface;
1677 IWineD3D_AddRef(object->wineD3D);
1678 object->parent = parent;
1680 /* Set the state up as invalid until the device is fully created */
1681 object->state = D3DERR_DRIVERINTERNALERROR;
1683 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %lx, PresParms: %p, RetDevInt: %p)\n", This, Adapter, DeviceType,
1684 hFocusWindow, BehaviourFlags, pPresentationParameters, ppReturnedDeviceInterface);
1685 TRACE("(%p)->(DepthStencil:(%u,%s), BackBufferFormat:(%u,%s))\n", This,
1686 *(pPresentationParameters->AutoDepthStencilFormat), debug_d3dformat(*(pPresentationParameters->AutoDepthStencilFormat)),
1687 *(pPresentationParameters->BackBufferFormat), debug_d3dformat(*(pPresentationParameters->BackBufferFormat)));
1689 /* Save the creation parameters */
1690 object->createParms.AdapterOrdinal = Adapter;
1691 object->createParms.DeviceType = DeviceType;
1692 object->createParms.hFocusWindow = hFocusWindow;
1693 object->createParms.BehaviorFlags = BehaviourFlags;
1695 /* Initialize other useful values */
1696 object->adapterNo = Adapter;
1697 object->devType = DeviceType;
1699 /* FIXME: Use for dx8 code eventually too! */
1700 /* Deliberately no indentation here, as this if will be removed when dx8 support merged in */
1701 if (This->dxVersion > 8) {
1702 TRACE("(%p) : Creating stateblock\n", This);
1703 /* Creating the startup stateBlock - Note Special Case: 0 => Don't fill in yet! */
1704 if (D3D_OK != IWineD3DDevice_CreateStateBlock((IWineD3DDevice *)object,
1705 WINED3DSBT_INIT,
1706 (IWineD3DStateBlock **)&object->stateBlock,
1707 NULL) || NULL == object->stateBlock) { /* Note: No parent needed for initial internal stateblock */
1708 WARN("Failed to create stateblock\n");
1709 goto create_device_error;
1711 TRACE("(%p) : Created stateblock (%p) \n", This, object->stateBlock);
1712 object->updateStateBlock = object->stateBlock;
1713 IWineD3DStateBlock_AddRef((IWineD3DStateBlock*)object->updateStateBlock);
1714 /* Setup surfaces for the backbuffer, frontbuffer and depthstencil buffer */
1716 /* Setup some defaults for creating the implicit swapchain */
1717 ENTER_GL();
1718 IWineD3DImpl_FillGLCaps(&This->gl_info, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
1719 LEAVE_GL();
1721 /* Setup the implicit swapchain */
1722 TRACE("Creating implicit swapchain\n");
1723 if (D3D_OK != D3DCB_CreateAdditionalSwapChain((IUnknown *) object->parent, pPresentationParameters, (IWineD3DSwapChain **)&swapchain) || swapchain == NULL) {
1724 WARN("Failed to create implicit swapchain\n");
1725 goto create_device_error;
1728 object->renderTarget = swapchain->backBuffer;
1729 IWineD3DSurface_AddRef(object->renderTarget);
1730 /* Depth Stencil support */
1731 object->stencilBufferTarget = object->depthStencilBuffer;
1732 if (NULL != object->stencilBufferTarget) {
1733 IWineD3DSurface_AddRef(object->stencilBufferTarget);
1736 /* Set up some starting GL setup */
1737 ENTER_GL();
1739 * Initialize openGL extension related variables
1740 * with Default values
1743 This->isGLInfoValid = IWineD3DImpl_FillGLCaps(&This->gl_info, swapchain->display);
1744 /* Setup all the devices defaults */
1745 IWineD3DStateBlock_InitStartupStateBlock((IWineD3DStateBlock *)object->stateBlock);
1746 #if 0
1747 IWineD3DImpl_CheckGraphicsMemory();
1748 #endif
1749 LEAVE_GL();
1751 { /* Set a default viewport */
1752 D3DVIEWPORT9 vp;
1753 vp.X = 0;
1754 vp.Y = 0;
1755 vp.Width = *(pPresentationParameters->BackBufferWidth);
1756 vp.Height = *(pPresentationParameters->BackBufferHeight);
1757 vp.MinZ = 0.0f;
1758 vp.MaxZ = 1.0f;
1759 IWineD3DDevice_SetViewport((IWineD3DDevice *)object, &vp);
1763 /* Initialize the current view state */
1764 object->modelview_valid = 1;
1765 object->proj_valid = 0;
1766 object->view_ident = 1;
1767 object->last_was_rhw = 0;
1768 glGetIntegerv(GL_MAX_LIGHTS, &object->maxConcurrentLights);
1769 TRACE("(%p,%d) All defaults now set up, leaving CreateDevice with %p\n", This, Adapter, object);
1771 /* Clear the screen */
1772 IWineD3DDevice_Clear((IWineD3DDevice *) object, 0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET, 0x00, 1.0, 0);
1774 } else { /* End of FIXME: remove when dx8 merged in */
1776 FIXME("(%p) Incomplete stub for d3d8\n", This);
1780 /* set the state of the device to valid */
1781 object->state = D3D_OK;
1783 return D3D_OK;
1784 create_device_error:
1786 /* Set the device state to error */
1787 object->state = D3DERR_DRIVERINTERNALERROR;
1789 if (object->updateStateBlock != NULL) {
1790 IWineD3DStateBlock_Release((IWineD3DStateBlock *)object->updateStateBlock);
1791 object->updateStateBlock = NULL;
1793 if (object->stateBlock != NULL) {
1794 IWineD3DStateBlock_Release((IWineD3DStateBlock *)object->stateBlock);
1795 object->stateBlock = NULL;
1797 if (object->renderTarget != NULL) {
1798 IWineD3DSurface_Release(object->renderTarget);
1799 object->renderTarget = NULL;
1801 if (object->stencilBufferTarget != NULL) {
1802 IWineD3DSurface_Release(object->stencilBufferTarget);
1803 object->stencilBufferTarget = NULL;
1805 if (object->stencilBufferTarget != NULL) {
1806 IWineD3DSurface_Release(object->stencilBufferTarget);
1807 object->stencilBufferTarget = NULL;
1809 if (swapchain != NULL) {
1810 IWineD3DSwapChain_Release((IWineD3DSwapChain *)swapchain);
1811 swapchain = NULL;
1813 HeapFree(GetProcessHeap(), 0, object);
1814 *ppReturnedDeviceInterface = NULL;
1815 return D3DERR_INVALIDCALL;
1819 HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
1820 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1821 IUnknown_AddRef(This->parent);
1822 *pParent = This->parent;
1823 return D3D_OK;
1826 /**********************************************************
1827 * IWineD3D VTbl follows
1828 **********************************************************/
1830 const IWineD3DVtbl IWineD3D_Vtbl =
1832 /* IUnknown */
1833 IWineD3DImpl_QueryInterface,
1834 IWineD3DImpl_AddRef,
1835 IWineD3DImpl_Release,
1836 /* IWineD3D */
1837 IWineD3DImpl_GetParent,
1838 IWineD3DImpl_GetAdapterCount,
1839 IWineD3DImpl_RegisterSoftwareDevice,
1840 IWineD3DImpl_GetAdapterMonitor,
1841 IWineD3DImpl_GetAdapterModeCount,
1842 IWineD3DImpl_EnumAdapterModes,
1843 IWineD3DImpl_GetAdapterDisplayMode,
1844 IWineD3DImpl_GetAdapterIdentifier,
1845 IWineD3DImpl_CheckDeviceMultiSampleType,
1846 IWineD3DImpl_CheckDepthStencilMatch,
1847 IWineD3DImpl_CheckDeviceType,
1848 IWineD3DImpl_CheckDeviceFormat,
1849 IWineD3DImpl_CheckDeviceFormatConversion,
1850 IWineD3DImpl_GetDeviceCaps,
1851 IWineD3DImpl_CreateDevice