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*/
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 )
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;
62 int minLookup[MAX_LOOKUPS];
63 int maxLookup[MAX_LOOKUPS];
64 DWORD *stateLookup[MAX_LOOKUPS];
66 DWORD minMipLookup[D3DTEXF_ANISOTROPIC + 1][D3DTEXF_LINEAR + 1];
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;
87 XWindowAttributes win_attr;
89 TRACE_(d3d_caps)("Creating Fake GL Context\n");
91 ctx.drawable = (Drawable) GetPropA(GetDesktopWindow(), "__wine_x11_whole_window");
94 device_context = GetDC(0);
95 ctx.display = get_display(device_context);
96 ReleaseDC(0, device_context);
98 /* Get the X visual */
100 if (XGetWindowAttributes(ctx.display, ctx.drawable, &win_attr)) {
101 visual = win_attr.visual;
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) {
109 WARN_(d3d_caps)("Error creating visual info for capabilities initialization\n");
113 /* Create a GL context */
115 ctx.glCtx = glXCreateContext(ctx.display, ctx.visInfo, NULL, GL_TRUE);
117 if (ctx.glCtx == NULL) {
119 WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
124 /* Make it the current GL context */
125 if (!failed && glXMakeCurrent(ctx.display, ctx.drawable, ctx.glCtx) == False) {
126 glXDestroyContext(ctx.display, ctx.glCtx);
128 WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
132 /* It worked! Wow... */
142 if (ctx.ref > 0) ret = &ctx;
145 if (NULL != ret) InterlockedIncrement(&ret->ref);
149 static void WineD3D_ReleaseFakeGLContext(WineD3D_Context* ctx) {
150 /* If we created a dummy context, throw it away */
152 if (0 == InterlockedDecrement(&ctx->ref)) {
153 glXMakeCurrent(ctx->display, None, NULL);
154 glXDestroyContext(ctx->display, ctx->glCtx);
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);
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);
190 ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
191 IWineD3DImpl *This = (IWineD3DImpl *)iface;
193 TRACE("(%p) : Releasing from %ld\n", This, This->ref);
194 ref = InterlockedDecrement(&This->ref);
196 HeapFree(GetProcessHeap(), 0, This);
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;
215 WineD3D_Context *fake_ctx = NULL;
216 BOOL gotContext = FALSE;
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;
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);
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 if (strstr(gl_string, "Mesa")) {
248 gl_info->gl_vendor = VENDOR_MESA;
250 gl_info->gl_vendor = VENDOR_WINE;
253 gl_info->gl_vendor = VENDOR_WINE;
257 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
259 /* Parse the GL_VERSION field into major and minor information */
260 gl_string = (const char *) glGetString(GL_VERSION);
261 if (gl_string != NULL) {
263 switch (gl_info->gl_vendor) {
265 gl_string_cursor = strstr(gl_string, "NVIDIA");
266 gl_string_cursor = strstr(gl_string_cursor, " ");
267 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
268 if (*gl_string_cursor) {
272 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
273 tmp[cursor++] = *gl_string_cursor;
279 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
283 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
284 tmp[cursor++] = *gl_string_cursor;
294 gl_string_cursor = strchr(gl_string, '-');
295 if (gl_string_cursor) {
299 /* Check if version number is of the form x.y.z */
300 if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
302 if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
304 if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
306 if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
309 /* Mark version number as malformed */
311 gl_string_cursor = 0;
314 if (!gl_string_cursor)
315 WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
317 major = *gl_string_cursor - '0';
318 minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
323 gl_string_cursor = strstr(gl_string, "Mesa");
324 gl_string_cursor = strstr(gl_string_cursor, " ");
325 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
326 if (*gl_string_cursor) {
330 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
331 tmp[cursor++] = *gl_string_cursor;
337 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
341 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
342 tmp[cursor++] = *gl_string_cursor;
354 gl_info->gl_driver_version = MAKEDWORD_VERSION(major, minor);
355 TRACE_(d3d_caps)("found GL_VERSION (%s)->(0x%08lx)\n", debugstr_a(gl_string), gl_info->gl_driver_version);
357 /* Fill in the renderer information */
358 gl_string = (const char *) glGetString(GL_RENDERER);
359 strcpy(gl_info->gl_renderer, gl_string);
361 switch (gl_info->gl_vendor) {
363 if (strstr(gl_info->gl_renderer, "GeForce4 Ti")) {
364 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4600;
365 } else if (strstr(gl_info->gl_renderer, "GeForceFX")) {
366 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5900ULTRA;
368 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4600;
373 if (strstr(gl_info->gl_renderer, "RADEON 9800 PRO")) {
374 gl_info->gl_card = CARD_ATI_RADEON_9800PRO;
375 } else if (strstr(gl_info->gl_renderer, "RADEON 9700 PRO")) {
376 gl_info->gl_card = CARD_ATI_RADEON_9700PRO;
378 gl_info->gl_card = CARD_ATI_RADEON_8500;
383 gl_info->gl_card = CARD_WINE;
387 FIXME("get version string returned null\n");
390 TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
393 * Initialize openGL extension related variables
394 * with Default values
396 memset(&gl_info->supported, 0, sizeof(gl_info->supported));
397 gl_info->max_textures = 1;
398 gl_info->max_samplers = 1;
399 gl_info->ps_arb_version = PS_VERSION_NOT_SUPPORTED;
400 gl_info->vs_arb_version = VS_VERSION_NOT_SUPPORTED;
401 gl_info->vs_nv_version = VS_VERSION_NOT_SUPPORTED;
402 gl_info->vs_ati_version = VS_VERSION_NOT_SUPPORTED;
404 /* Now work out what GL support this card really has */
405 #define USE_GL_FUNC(type, pfn) gl_info->pfn = NULL;
409 /* Retrieve opengl defaults */
410 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
411 gl_info->max_clipplanes = min(D3DMAXUSERCLIPPLANES, gl_max);
412 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
414 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
415 gl_info->max_lights = gl_max;
416 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
418 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
419 gl_info->max_texture_size = gl_max;
420 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
422 glGetFloatv(GL_POINT_SIZE_RANGE, &gl_float);
423 gl_info->max_pointsize = gl_float;
424 TRACE_(d3d_caps)("Maximum point size support - max texture size=%f\n", gl_float);
426 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
427 GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
428 TRACE_(d3d_caps)("GL_Extensions reported:\n");
430 if (NULL == GL_Extensions) {
431 ERR(" GL_Extensions returns NULL\n");
433 while (*GL_Extensions != 0x00) {
434 const char *Start = GL_Extensions;
437 memset(ThisExtn, 0x00, sizeof(ThisExtn));
438 while (*GL_Extensions != ' ' && *GL_Extensions != 0x00) {
441 memcpy(ThisExtn, Start, (GL_Extensions - Start));
442 TRACE_(d3d_caps)("- %s\n", ThisExtn);
447 if (strcmp(ThisExtn, "GL_ARB_fragment_program") == 0) {
448 gl_info->ps_arb_version = PS_VERSION_11;
449 TRACE_(d3d_caps)(" FOUND: ARB Pixel Shader support - version=%02x\n", gl_info->ps_arb_version);
450 gl_info->supported[ARB_FRAGMENT_PROGRAM] = TRUE;
451 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &gl_max);
452 TRACE_(d3d_caps)(" FOUND: ARB Pixel Shader support - GL_MAX_TEXTURE_IMAGE_UNITS_ARB=%u\n", gl_max);
453 gl_info->max_samplers = min(MAX_SAMPLERS, gl_max);
454 } else if (strcmp(ThisExtn, "GL_ARB_multisample") == 0) {
455 TRACE_(d3d_caps)(" FOUND: ARB Multisample support\n");
456 gl_info->supported[ARB_MULTISAMPLE] = TRUE;
457 } else if (strcmp(ThisExtn, "GL_ARB_multitexture") == 0) {
458 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
459 TRACE_(d3d_caps)(" FOUND: ARB Multitexture support - GL_MAX_TEXTURE_UNITS_ARB=%u\n", gl_max);
460 gl_info->supported[ARB_MULTITEXTURE] = TRUE;
461 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
462 gl_info->max_samplers = max(gl_info->max_samplers, gl_max);
463 } else if (strcmp(ThisExtn, "GL_ARB_texture_cube_map") == 0) {
464 TRACE_(d3d_caps)(" FOUND: ARB Texture Cube Map support\n");
465 gl_info->supported[ARB_TEXTURE_CUBE_MAP] = TRUE;
466 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
467 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
468 } else if (strcmp(ThisExtn, "GL_ARB_texture_compression") == 0) {
469 TRACE_(d3d_caps)(" FOUND: ARB Texture Compression support\n");
470 gl_info->supported[ARB_TEXTURE_COMPRESSION] = TRUE;
471 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_add") == 0) {
472 TRACE_(d3d_caps)(" FOUND: ARB Texture Env Add support\n");
473 gl_info->supported[ARB_TEXTURE_ENV_ADD] = TRUE;
474 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_combine") == 0) {
475 TRACE_(d3d_caps)(" FOUND: ARB Texture Env combine support\n");
476 gl_info->supported[ARB_TEXTURE_ENV_COMBINE] = TRUE;
477 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_dot3") == 0) {
478 TRACE_(d3d_caps)(" FOUND: ARB Dot3 support\n");
479 gl_info->supported[ARB_TEXTURE_ENV_DOT3] = TRUE;
480 } else if (strcmp(ThisExtn, "GL_ARB_texture_border_clamp") == 0) {
481 TRACE_(d3d_caps)(" FOUND: ARB Texture border clamp support\n");
482 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] = TRUE;
483 } else if (strcmp(ThisExtn, "GL_ARB_texture_mirrored_repeat") == 0) {
484 TRACE_(d3d_caps)(" FOUND: ARB Texture mirrored repeat support\n");
485 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] = TRUE;
486 } else if (strcmp(ThisExtn, "GLX_ARB_multisample") == 0) {
487 TRACE_(d3d_caps)(" FOUND: ARB multisample support\n");
488 gl_info->supported[ARB_MULTISAMPLE] = TRUE;
489 } else if (strcmp(ThisExtn, "GL_ARB_pixel_buffer_object") == 0) {
490 TRACE_(d3d_caps)(" FOUND: ARB Pixel Buffer support\n");
491 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = TRUE;
492 } else if (strcmp(ThisExtn, "GL_ARB_point_sprite") == 0) {
493 TRACE_(d3d_caps)(" FOUND: ARB point sprite support\n");
494 gl_info->supported[ARB_POINT_SPRITE] = TRUE;
495 } else if (strstr(ThisExtn, "GL_ARB_vertex_program")) {
496 gl_info->vs_arb_version = VS_VERSION_11;
497 TRACE_(d3d_caps)(" FOUND: ARB Vertex Shader support - version=%02x\n", gl_info->vs_arb_version);
498 gl_info->supported[ARB_VERTEX_PROGRAM] = TRUE;
499 } else if (strcmp(ThisExtn, "GL_ARB_vertex_blend") == 0) {
500 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
501 TRACE_(d3d_caps)(" FOUND: ARB Vertex Blend support GL_MAX_VERTEX_UNITS_ARB %d\n", gl_max);
502 gl_info->max_blends = gl_max;
503 gl_info->supported[ARB_VERTEX_BLEND] = TRUE;
504 } else if (strcmp(ThisExtn, "GL_ARB_vertex_buffer_object") == 0) {
505 TRACE_(d3d_caps)(" FOUND: ARB Vertex Buffer support\n");
506 gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] = TRUE;
507 } else if (strcmp(ThisExtn, "GL_ARB_occlusion_query") == 0) {
508 TRACE_(d3d_caps)(" FOUND: ARB Occlusion Query support\n");
509 gl_info->supported[ARB_OCCLUSION_QUERY] = TRUE;
513 } else if (strcmp(ThisExtn, "GL_EXT_fog_coord") == 0) {
514 TRACE_(d3d_caps)(" FOUND: EXT Fog coord support\n");
515 gl_info->supported[EXT_FOG_COORD] = TRUE;
516 } else if (strcmp(ThisExtn, "GL_EXT_framebuffer_object") == 0) {
517 TRACE_(d3d_caps)(" FOUND: EXT Frame Buffer Object support\n");
518 gl_info->supported[EXT_FRAMEBUFFER_OBJECT] = TRUE;
519 } else if (strcmp(ThisExtn, "GL_EXT_paletted_texture") == 0) { /* handle paletted texture extensions */
520 TRACE_(d3d_caps)(" FOUND: EXT Paletted texture support\n");
521 gl_info->supported[EXT_PALETTED_TEXTURE] = TRUE;
522 } else if (strcmp(ThisExtn, "GL_EXT_point_parameters") == 0) {
523 TRACE_(d3d_caps)(" FOUND: EXT Point parameters support\n");
524 gl_info->supported[EXT_POINT_PARAMETERS] = TRUE;
525 } else if (strcmp(ThisExtn, "GL_EXT_secondary_color") == 0) {
526 TRACE_(d3d_caps)(" FOUND: EXT Secondary coord support\n");
527 gl_info->supported[EXT_SECONDARY_COLOR] = TRUE;
528 } else if (strcmp(ThisExtn, "GL_EXT_stencil_wrap") == 0) {
529 TRACE_(d3d_caps)(" FOUND: EXT Stencil wrap support\n");
530 gl_info->supported[EXT_STENCIL_WRAP] = TRUE;
531 } else if (strcmp(ThisExtn, "GL_EXT_texture_compression_s3tc") == 0) {
532 TRACE_(d3d_caps)(" FOUND: EXT Texture S3TC compression support\n");
533 gl_info->supported[EXT_TEXTURE_COMPRESSION_S3TC] = TRUE;
534 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_add") == 0) {
535 TRACE_(d3d_caps)(" FOUND: EXT Texture Env Add support\n");
536 gl_info->supported[EXT_TEXTURE_ENV_ADD] = TRUE;
537 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_combine") == 0) {
538 TRACE_(d3d_caps)(" FOUND: EXT Texture Env combine support\n");
539 gl_info->supported[EXT_TEXTURE_ENV_COMBINE] = TRUE;
540 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_dot3") == 0) {
541 TRACE_(d3d_caps)(" FOUND: EXT Dot3 support\n");
542 gl_info->supported[EXT_TEXTURE_ENV_DOT3] = TRUE;
543 } else if (strcmp(ThisExtn, "GL_EXT_texture_filter_anisotropic") == 0) {
544 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] = TRUE;
545 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
546 TRACE_(d3d_caps)(" FOUND: EXT Texture Anisotropic filter support. GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT %d\n", gl_max);
547 gl_info->max_anisotropy = gl_max;
548 } else if (strcmp(ThisExtn, "GL_EXT_texture_lod") == 0) {
549 TRACE_(d3d_caps)(" FOUND: EXT Texture LOD support\n");
550 gl_info->supported[EXT_TEXTURE_LOD] = TRUE;
551 } else if (strcmp(ThisExtn, "GL_EXT_texture_lod_bias") == 0) {
552 TRACE_(d3d_caps)(" FOUND: EXT Texture LOD bias support\n");
553 gl_info->supported[EXT_TEXTURE_LOD_BIAS] = TRUE;
554 } else if (strcmp(ThisExtn, "GL_EXT_vertex_weighting") == 0) {
555 TRACE_(d3d_caps)(" FOUND: EXT Vertex weighting support\n");
556 gl_info->supported[EXT_VERTEX_WEIGHTING] = TRUE;
561 } else if (strstr(ThisExtn, "GL_NV_fog_distance")) {
562 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Fog Distance support\n");
563 gl_info->supported[NV_FOG_DISTANCE] = TRUE;
564 } else if (strstr(ThisExtn, "GL_NV_fragment_program")) {
565 gl_info->ps_nv_version = PS_VERSION_11;
566 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Pixel Shader support - version=%02x\n", gl_info->ps_nv_version);
567 } else if (strcmp(ThisExtn, "GL_NV_register_combiners") == 0) {
568 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Register combiners (1) support\n");
569 gl_info->supported[NV_REGISTER_COMBINERS] = TRUE;
570 } else if (strcmp(ThisExtn, "GL_NV_register_combiners2") == 0) {
571 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Register combiners (2) support\n");
572 gl_info->supported[NV_REGISTER_COMBINERS2] = TRUE;
573 } else if (strcmp(ThisExtn, "GL_NV_texgen_reflection") == 0) {
574 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Gen Reflection support\n");
575 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
576 } else if (strcmp(ThisExtn, "GL_NV_texture_env_combine4") == 0) {
577 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Env combine (4) support\n");
578 gl_info->supported[NV_TEXTURE_ENV_COMBINE4] = TRUE;
579 } else if (strcmp(ThisExtn, "GL_NV_texture_shader") == 0) {
580 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (1) support\n");
581 gl_info->supported[NV_TEXTURE_SHADER] = TRUE;
582 } else if (strcmp(ThisExtn, "GL_NV_texture_shader2") == 0) {
583 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (2) support\n");
584 gl_info->supported[NV_TEXTURE_SHADER2] = TRUE;
585 } else if (strcmp(ThisExtn, "GL_NV_texture_shader3") == 0) {
586 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (3) support\n");
587 gl_info->supported[NV_TEXTURE_SHADER3] = TRUE;
588 } else if (strcmp(ThisExtn, "GL_NV_occlusion_query") == 0) {
589 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Occlusion Query (3) support\n");
590 gl_info->supported[NV_OCCLUSION_QUERY] = TRUE;
591 } else if (strstr(ThisExtn, "GL_NV_vertex_program")) {
592 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);
593 gl_info->vs_nv_version = max(gl_info->vs_nv_version, (0 == strcmp(ThisExtn, "GL_NV_vertex_program2")) ? VS_VERSION_20 : VS_VERSION_10);
594 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Vertex Shader support - version=%02x\n", gl_info->vs_nv_version);
595 gl_info->supported[NV_VERTEX_PROGRAM] = TRUE;
601 } else if (strcmp(ThisExtn, "GL_ATI_texture_env_combine3") == 0) {
602 TRACE_(d3d_caps)(" FOUND: ATI Texture Env combine (3) support\n");
603 gl_info->supported[ATI_TEXTURE_ENV_COMBINE3] = TRUE;
604 } else if (strcmp(ThisExtn, "GL_ATI_texture_mirror_once") == 0) {
605 TRACE_(d3d_caps)(" FOUND: ATI Texture Mirror Once support\n");
606 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] = TRUE;
607 } else if (strcmp(ThisExtn, "GL_EXT_vertex_shader") == 0) {
608 gl_info->vs_ati_version = VS_VERSION_11;
609 TRACE_(d3d_caps)(" FOUND: ATI (EXT) Vertex Shader support - version=%02x\n", gl_info->vs_ati_version);
610 gl_info->supported[EXT_VERTEX_SHADER] = TRUE;
614 if (*GL_Extensions == ' ') GL_Extensions++;
618 /* Load all the lookup tables
619 TODO: It may be a good idea to make minLookup and maxLookup const and populate them in wined3d_private.h where they are declared */
620 minLookup[WINELOOKUP_WARPPARAM] = D3DTADDRESS_WRAP;
621 maxLookup[WINELOOKUP_WARPPARAM] = D3DTADDRESS_MIRRORONCE;
623 minLookup[WINELOOKUP_MAGFILTER] = D3DTEXF_NONE;
624 maxLookup[WINELOOKUP_MAGFILTER] = D3DTEXF_ANISOTROPIC;
627 for (i = 0; i < MAX_LOOKUPS; i++) {
628 stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
631 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
632 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
633 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
634 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
635 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
636 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
637 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
638 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
639 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
640 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
642 stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_NONE - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
643 stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_POINT - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
644 stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_LINEAR - minLookup[WINELOOKUP_MAGFILTER]] = GL_LINEAR;
645 stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_ANISOTROPIC - minLookup[WINELOOKUP_MAGFILTER]] =
646 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR : GL_NEAREST;
649 minMipLookup[D3DTEXF_NONE][D3DTEXF_NONE] = GL_LINEAR;
650 minMipLookup[D3DTEXF_NONE][D3DTEXF_POINT] = GL_LINEAR;
651 minMipLookup[D3DTEXF_NONE][D3DTEXF_LINEAR] = GL_LINEAR;
652 minMipLookup[D3DTEXF_POINT][D3DTEXF_NONE] = GL_NEAREST;
653 minMipLookup[D3DTEXF_POINT][D3DTEXF_POINT] = GL_NEAREST_MIPMAP_NEAREST;
654 minMipLookup[D3DTEXF_POINT][D3DTEXF_LINEAR] = GL_NEAREST_MIPMAP_LINEAR;
655 minMipLookup[D3DTEXF_LINEAR][D3DTEXF_NONE] = GL_LINEAR;
656 minMipLookup[D3DTEXF_LINEAR][D3DTEXF_POINT] = GL_LINEAR_MIPMAP_NEAREST;
657 minMipLookup[D3DTEXF_LINEAR][D3DTEXF_LINEAR] = GL_LINEAR_MIPMAP_LINEAR;
658 minMipLookup[D3DTEXF_ANISOTROPIC][D3DTEXF_NONE] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ?
659 GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
660 minMipLookup[D3DTEXF_ANISOTROPIC][D3DTEXF_POINT] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR;
661 minMipLookup[D3DTEXF_ANISOTROPIC][D3DTEXF_LINEAR] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
663 /* TODO: config lookups */
666 #define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) glXGetProcAddressARB( (const GLubyte *) #pfn);
670 if (display != NULL) {
671 GLX_Extensions = glXQueryExtensionsString(display, DefaultScreen(display));
672 TRACE_(d3d_caps)("GLX_Extensions reported:\n");
674 if (NULL == GLX_Extensions) {
675 ERR(" GLX_Extensions returns NULL\n");
677 while (*GLX_Extensions != 0x00) {
678 const char *Start = GLX_Extensions;
681 memset(ThisExtn, 0x00, sizeof(ThisExtn));
682 while (*GLX_Extensions != ' ' && *GLX_Extensions != 0x00) {
685 memcpy(ThisExtn, Start, (GLX_Extensions - Start));
686 TRACE_(d3d_caps)("- %s\n", ThisExtn);
687 if (*GLX_Extensions == ' ') GLX_Extensions++;
692 #define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) glXGetProcAddressARB( (const GLubyte *) #pfn);
696 /* If we created a dummy context, throw it away */
697 if (NULL != fake_ctx) WineD3D_ReleaseFakeGLContext(fake_ctx);
699 /* Only save the values obtained when a display is provided */
700 if (fake_ctx == NULL) {
707 /**********************************************************
708 * IWineD3D implementation follows
709 **********************************************************/
711 UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
712 IWineD3DImpl *This = (IWineD3DImpl *)iface;
714 /* FIXME: Set to one for now to imply the display */
715 TRACE_(d3d_caps)("(%p): Mostly stub, only returns primary display\n", This);
719 HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
720 IWineD3DImpl *This = (IWineD3DImpl *)iface;
721 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
725 HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
726 IWineD3DImpl *This = (IWineD3DImpl *)iface;
727 FIXME_(d3d_caps)("(%p)->(Adptr:%d)\n", This, Adapter);
728 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
734 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
735 of the same bpp but different resolutions */
737 /* Note: dx9 supplies a format. Calls from d3d8 supply D3DFMT_UNKNOWN */
738 UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
739 IWineD3DImpl *This = (IWineD3DImpl *)iface;
740 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
742 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
746 if (Adapter == 0) { /* Display */
749 #if !defined( DEBUG_SINGLE_MODE )
752 /* Work out the current screen bpp */
753 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
754 int bpp = GetDeviceCaps(hdc, BITSPIXEL);
757 while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
764 case D3DFMT_X8R8G8B8:
765 case D3DFMT_A8R8G8B8:
766 if (min(DevModeW.dmBitsPerPel, bpp) == 32) i++;
767 if (min(DevModeW.dmBitsPerPel, bpp) == 24) i++;
769 case D3DFMT_X1R5G5B5:
770 case D3DFMT_A1R5G5B5:
772 if (min(DevModeW.dmBitsPerPel, bpp) == 16) i++;
775 /* Skip other modes as they do not match requested format */
783 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
786 FIXME_(d3d_caps)("Adapter not primary display\n");
791 /* Note: dx9 supplies a format. Calls from d3d8 supply D3DFMT_UNKNOWN */
792 HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) {
793 IWineD3DImpl *This = (IWineD3DImpl *)iface;
794 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
796 /* Validate the parameters as much as possible */
798 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
799 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
800 return D3DERR_INVALIDCALL;
803 if (Adapter == 0) { /* Display */
804 #if !defined( DEBUG_SINGLE_MODE )
808 /* Work out the current screen bpp */
809 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
810 int bpp = GetDeviceCaps(hdc, BITSPIXEL);
813 /* If we are filtering to a specific format, then need to skip all unrelated
814 modes, but if mode is irrelevant, then we can use the index directly */
815 if (Format == D3DFMT_UNKNOWN)
821 DEVMODEW DevModeWtmp;
824 while (i<(Mode) && EnumDisplaySettingsExW(NULL, j, &DevModeWtmp, 0)) {
831 case D3DFMT_X8R8G8B8:
832 case D3DFMT_A8R8G8B8:
833 if (min(DevModeWtmp.dmBitsPerPel, bpp) == 32) i++;
834 if (min(DevModeWtmp.dmBitsPerPel, bpp) == 24) i++;
836 case D3DFMT_X1R5G5B5:
837 case D3DFMT_A1R5G5B5:
839 if (min(DevModeWtmp.dmBitsPerPel, bpp) == 16) i++;
842 /* Skip other modes as they do not match requested format */
849 /* Now get the display mode via the calculated index */
850 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0))
852 pMode->Width = DevModeW.dmPelsWidth;
853 pMode->Height = DevModeW.dmPelsHeight;
854 bpp = min(DevModeW.dmBitsPerPel, bpp);
855 pMode->RefreshRate = D3DADAPTER_DEFAULT;
856 if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
858 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
861 if (Format == D3DFMT_UNKNOWN)
864 case 8: pMode->Format = D3DFMT_R3G3B2; break;
865 case 16: pMode->Format = D3DFMT_R5G6B5; break;
866 case 24: /* Robots and EVE Online need 24 and 32 bit as A8R8G8B8 to start */
867 case 32: pMode->Format = D3DFMT_A8R8G8B8; break;
868 default: pMode->Format = D3DFMT_UNKNOWN;
871 pMode->Format = Format;
876 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
877 return D3DERR_INVALIDCALL;
881 /* Return one setting of the format requested */
882 if (Mode > 0) return D3DERR_INVALIDCALL;
885 pMode->RefreshRate = D3DADAPTER_DEFAULT;
886 pMode->Format = (Format == D3DFMT_UNKNOWN) ? D3DFMT_A8R8G8B8 : Format;
889 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
890 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format), bpp);
893 FIXME_(d3d_caps)("Adapter not primary display\n");
899 HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
900 IWineD3DImpl *This = (IWineD3DImpl *)iface;
901 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
904 Adapter >= IWineD3D_GetAdapterCount(iface)) {
905 return D3DERR_INVALIDCALL;
908 if (Adapter == 0) { /* Display */
912 EnumDisplaySettingsExW(NULL, (DWORD)-1, &DevModeW, 0);
913 pMode->Width = DevModeW.dmPelsWidth;
914 pMode->Height = DevModeW.dmPelsHeight;
915 bpp = DevModeW.dmBitsPerPel;
916 pMode->RefreshRate = D3DADAPTER_DEFAULT;
917 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
919 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
923 case 8: pMode->Format = D3DFMT_R3G3B2; break;
924 case 16: pMode->Format = D3DFMT_R5G6B5; break;
925 case 24: pMode->Format = D3DFMT_X8R8G8B8; break; /* Robots needs 24bit to be X8R8G8B8 */
926 case 32: pMode->Format = D3DFMT_X8R8G8B8; break; /* EVE online and the Fur demo need 32bit AdapterDisplatMode to return X8R8G8B8 */
927 default: pMode->Format = D3DFMT_UNKNOWN;
931 FIXME_(d3d_caps)("Adapter not primary display\n");
934 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
935 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
939 static Display * WINAPI IWineD3DImpl_GetAdapterDisplay(IWineD3D *iface, UINT Adapter) {
942 /* only works with one adapter at the moment... */
944 /* Get the display */
945 device_context = GetDC(0);
946 display = get_display(device_context);
947 ReleaseDC(0, device_context);
951 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
952 and fields being inserted in the middle, a new structure is used in place */
953 HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
954 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
955 IWineD3DImpl *This = (IWineD3DImpl *)iface;
957 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %lx, pId=%p)\n", This, Adapter, Flags, pIdentifier);
959 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
960 return D3DERR_INVALIDCALL;
963 if (Adapter == 0) { /* Display - only device supported for now */
965 BOOL isGLInfoValid = This->isGLInfoValid;
967 /* FillGLCaps updates gl_info, but we only want to store and
968 reuse the values once we have a context which is valid. Values from
969 a temporary context may differ from the final ones */
970 if (isGLInfoValid == FALSE) {
971 /* If we don't know the device settings, go query them now */
972 isGLInfoValid = IWineD3DImpl_FillGLCaps(&This->gl_info, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
975 /* If it worked, return the information requested */
977 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
978 strcpy(pIdentifier->Driver, "Display");
979 strcpy(pIdentifier->Description, "Direct3D HAL");
981 /* Note dx8 doesn't supply a DeviceName */
982 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
983 pIdentifier->DriverVersion->u.HighPart = 0xa;
984 pIdentifier->DriverVersion->u.LowPart = This->gl_info.gl_driver_version;
985 *(pIdentifier->VendorId) = This->gl_info.gl_vendor;
986 *(pIdentifier->DeviceId) = This->gl_info.gl_card;
987 *(pIdentifier->SubSysId) = 0;
988 *(pIdentifier->Revision) = 0;
992 /* If it failed, return dummy values from an NVidia driver */
993 WARN_(d3d_caps)("Cannot get GLCaps for device/Vendor Name and Version detection using FillGLCaps, currently using NVIDIA identifiers\n");
994 strcpy(pIdentifier->Driver, "Display");
995 strcpy(pIdentifier->Description, "Direct3D HAL");
996 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
997 pIdentifier->DriverVersion->u.HighPart = 0xa;
998 pIdentifier->DriverVersion->u.LowPart = MAKEDWORD_VERSION(53, 96); /* last Linux Nvidia drivers */
999 *(pIdentifier->VendorId) = VENDOR_NVIDIA;
1000 *(pIdentifier->DeviceId) = CARD_NVIDIA_GEFORCE4_TI4600;
1001 *(pIdentifier->SubSysId) = 0;
1002 *(pIdentifier->Revision) = 0;
1005 /*FIXME: memcpy(&pIdentifier->DeviceIdentifier, ??, sizeof(??GUID)); */
1006 if (Flags & D3DENUM_NO_WHQL_LEVEL) {
1007 *(pIdentifier->WHQLLevel) = 0;
1009 *(pIdentifier->WHQLLevel) = 1;
1013 FIXME_(d3d_caps)("Adapter not primary display\n");
1019 static BOOL IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(WineD3D_Context* ctx, GLXFBConfig cfgs, WINED3DFORMAT Format) {
1020 #if 0 /* This code performs a strict test between the format and the current X11 buffer depth, which may give the best performance */
1022 int rb, gb, bb, ab, type, buf_sz;
1024 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_RED_SIZE, &rb);
1025 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_GREEN_SIZE, &gb);
1026 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_BLUE_SIZE, &bb);
1027 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_ALPHA_SIZE, &ab);
1028 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_RENDER_TYPE, &type);
1029 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_BUFFER_SIZE, &buf_sz);
1032 case WINED3DFMT_X8R8G8B8:
1033 case WINED3DFMT_R8G8B8:
1034 if (8 == rb && 8 == gb && 8 == bb) return TRUE;
1036 case WINED3DFMT_A8R8G8B8:
1037 if (8 == rb && 8 == gb && 8 == bb && 8 == ab) return TRUE;
1039 case WINED3DFMT_A2R10G10B10:
1040 if (10 == rb && 10 == gb && 10 == bb && 2 == ab) return TRUE;
1042 case WINED3DFMT_X1R5G5B5:
1043 if (5 == rb && 5 == gb && 5 == bb) return TRUE;
1045 case WINED3DFMT_A1R5G5B5:
1046 if (5 == rb && 5 == gb && 5 == bb && 1 == ab) return TRUE;
1048 case WINED3DFMT_R5G6B5:
1049 if (5 == rb && 6 == gb && 5 == bb) return TRUE;
1051 case WINED3DFMT_R3G3B2:
1052 if (3 == rb && 3 == gb && 2 == bb) return TRUE;
1054 case WINED3DFMT_A8P8:
1055 if (type & GLX_COLOR_INDEX_BIT && 8 == buf_sz && 8 == ab) return TRUE;
1058 if (type & GLX_COLOR_INDEX_BIT && 8 == buf_sz) return TRUE;
1061 ERR("unsupported format %s\n", debug_d3dformat(Format));
1065 #else /* Most of the time performance is less of an issue than compatibility, this code allows for most common opengl/d3d formats */
1067 case WINED3DFMT_X8R8G8B8:
1068 case WINED3DFMT_R8G8B8:
1069 case WINED3DFMT_A8R8G8B8:
1070 case WINED3DFMT_A2R10G10B10:
1071 case WINED3DFMT_X1R5G5B5:
1072 case WINED3DFMT_A1R5G5B5:
1073 case WINED3DFMT_R5G6B5:
1074 case WINED3DFMT_R3G3B2:
1075 case WINED3DFMT_A8P8:
1079 ERR("unsupported format %s\n", debug_d3dformat(Format));
1086 static BOOL IWineD3DImpl_IsGLXFBConfigCompatibleWithDepthFmt(WineD3D_Context* ctx, GLXFBConfig cfgs, WINED3DFORMAT Format) {
1087 #if 0/* This code performs a strict test between the format and the current X11 buffer depth, which may give the best performance */
1091 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_DEPTH_SIZE, &db);
1092 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_STENCIL_SIZE, &sb);
1095 case WINED3DFMT_D16:
1096 case WINED3DFMT_D16_LOCKABLE:
1097 if (16 == db) return TRUE;
1099 case WINED3DFMT_D32:
1100 if (32 == db) return TRUE;
1102 case WINED3DFMT_D15S1:
1103 if (15 == db) return TRUE;
1105 case WINED3DFMT_D24S8:
1106 if (24 == db && 8 == sb) return TRUE;
1108 case WINED3DFMT_D24FS8:
1109 if (24 == db && 8 == sb) return TRUE;
1111 case WINED3DFMT_D24X8:
1112 if (24 == db) return TRUE;
1114 case WINED3DFMT_D24X4S4:
1115 if (24 == db && 4 == sb) return TRUE;
1117 case WINED3DFMT_D32F_LOCKABLE:
1118 if (32 == db) return TRUE;
1121 ERR("unsupported format %s\n", debug_d3dformat(Format));
1125 #else /* Most of the time performance is less of an issue than compatibility, this code allows for most common opengl/d3d formats */
1127 case WINED3DFMT_D16:
1128 case WINED3DFMT_D16_LOCKABLE:
1129 case WINED3DFMT_D32:
1130 case WINED3DFMT_D15S1:
1131 case WINED3DFMT_D24S8:
1132 case WINED3DFMT_D24FS8:
1133 case WINED3DFMT_D24X8:
1134 case WINED3DFMT_D24X4S4:
1135 case WINED3DFMT_D32F_LOCKABLE:
1138 ERR("unsupported format %s\n", debug_d3dformat(Format));
1145 HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1146 WINED3DFORMAT AdapterFormat,
1147 WINED3DFORMAT RenderTargetFormat,
1148 WINED3DFORMAT DepthStencilFormat) {
1149 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1150 HRESULT hr = D3DERR_NOTAVAILABLE;
1151 WineD3D_Context* ctx = NULL;
1152 GLXFBConfig* cfgs = NULL;
1156 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
1158 DeviceType, debug_d3ddevicetype(DeviceType),
1159 AdapterFormat, debug_d3dformat(AdapterFormat),
1160 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
1161 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
1163 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1164 TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning D3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
1165 return D3DERR_INVALIDCALL;
1167 /* TODO: use the real context if it's available */
1168 ctx = WineD3D_CreateFakeGLContext();
1170 cfgs = glXGetFBConfigs(ctx->display, DefaultScreen(ctx->display), &nCfgs);
1172 TRACE_(d3d_caps)("(%p) : Unable to create a fake context at this time (there may already be an active context)\n", This);
1176 for (it = 0; it < nCfgs; ++it) {
1177 if (IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(ctx, cfgs[it], RenderTargetFormat)) {
1178 if (IWineD3DImpl_IsGLXFBConfigCompatibleWithDepthFmt(ctx, cfgs[it], DepthStencilFormat)) {
1187 /* If there's a corrent context then we cannot create a fake one so pass everything */
1192 WineD3D_ReleaseFakeGLContext(ctx);
1195 TRACE_(d3d_caps)("Failed to match stencil format to device\b");
1197 TRACE_(d3d_caps)("(%p) : Returning %lx\n", This, hr);
1201 HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1202 WINED3DFORMAT SurfaceFormat,
1203 BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
1205 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1206 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
1209 DeviceType, debug_d3ddevicetype(DeviceType),
1210 SurfaceFormat, debug_d3dformat(SurfaceFormat),
1215 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1216 return D3DERR_INVALIDCALL;
1219 if (pQualityLevels != NULL) {
1220 static int s_single_shot = 0;
1221 if (!s_single_shot) {
1222 FIXME("Quality levels unsupported at present\n");
1225 *pQualityLevels = 1; /* Guess at a value! */
1228 if (D3DMULTISAMPLE_NONE == MultiSampleType) return D3D_OK;
1229 return D3DERR_NOTAVAILABLE;
1232 HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, D3DDEVTYPE CheckType,
1233 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
1235 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1236 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
1239 CheckType, debug_d3ddevicetype(CheckType),
1240 DisplayFormat, debug_d3dformat(DisplayFormat),
1241 BackBufferFormat, debug_d3dformat(BackBufferFormat),
1244 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1245 return D3DERR_INVALIDCALL;
1249 GLXFBConfig* cfgs = NULL;
1252 HRESULT hr = D3DERR_NOTAVAILABLE;
1254 WineD3D_Context* ctx = WineD3D_CreateFakeGLContext();
1256 cfgs = glXGetFBConfigs(ctx->display, DefaultScreen(ctx->display), &nCfgs);
1257 for (it = 0; it < nCfgs; ++it) {
1258 if (IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(ctx, cfgs[it], DisplayFormat)) {
1265 WineD3D_ReleaseFakeGLContext(ctx);
1270 return D3DERR_NOTAVAILABLE;
1273 HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1274 WINED3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat) {
1275 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1276 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%lu,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s)) ",
1279 DeviceType, debug_d3ddevicetype(DeviceType),
1280 AdapterFormat, debug_d3dformat(AdapterFormat),
1281 Usage, debug_d3dusage(Usage),
1282 RType, debug_d3dresourcetype(RType),
1283 CheckFormat, debug_d3dformat(CheckFormat));
1285 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1286 return D3DERR_INVALIDCALL;
1289 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1290 switch (CheckFormat) {
1296 TRACE_(d3d_caps)("[OK]\n");
1299 break; /* Avoid compiler warnings */
1303 switch (CheckFormat) {
1305 * check supported using GL_SUPPORT
1316 /*case D3DFMT_R5G6B5: */
1317 /*case D3DFMT_X1R5G5B5:*/
1318 /*case D3DFMT_A1R5G5B5: */
1319 /*case D3DFMT_A4R4G4B4:*/
1326 /*case D3DFMT_X8R8G8B8:*/
1327 case D3DFMT_A8R3G3B2:
1344 case D3DFMT_X8L8V8U8:
1345 case D3DFMT_Q8W8V8U8:
1346 case D3DFMT_W11V11U10:
1349 * currently hard to support
1354 /* Since we do not support these formats right now, don't pretend to. */
1355 TRACE_(d3d_caps)("[FAILED]\n");
1356 return D3DERR_NOTAVAILABLE;
1361 TRACE_(d3d_caps)("[OK]\n");
1365 HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1366 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
1367 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1369 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))",
1372 DeviceType, debug_d3ddevicetype(DeviceType),
1373 SourceFormat, debug_d3dformat(SourceFormat),
1374 TargetFormat, debug_d3dformat(TargetFormat));
1378 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
1379 subset of a D3DCAPS9 structure. However, it has to come via a void *
1380 as the d3d8 interface cannot import the d3d9 header */
1381 HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
1383 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1385 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
1387 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1388 return D3DERR_INVALIDCALL;
1391 /* If we don't know the device settings, go query them now */
1392 if (This->isGLInfoValid == FALSE) {
1393 /* use the desktop window to fill gl caps */
1394 BOOL rc = IWineD3DImpl_FillGLCaps(&This->gl_info, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
1396 /* We are running off a real context, save the values */
1397 if (rc) This->isGLInfoValid = TRUE;
1401 /* ------------------------------------------------
1402 The following fields apply to both d3d8 and d3d9
1403 ------------------------------------------------ */
1404 *pCaps->DeviceType = (DeviceType == D3DDEVTYPE_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
1405 *pCaps->AdapterOrdinal = Adapter;
1408 *pCaps->Caps2 = D3DCAPS2_CANRENDERWINDOWED;
1409 *pCaps->Caps3 = D3DDEVCAPS_HWTRANSFORMANDLIGHT;
1410 *pCaps->PresentationIntervals = D3DPRESENT_INTERVAL_IMMEDIATE;
1412 *pCaps->CursorCaps = 0;
1415 *pCaps->DevCaps = D3DDEVCAPS_DRAWPRIMTLVERTEX |
1416 D3DDEVCAPS_HWTRANSFORMANDLIGHT |
1417 D3DDEVCAPS_PUREDEVICE |
1418 D3DDEVCAPS_HWRASTERIZATION;
1421 *pCaps->PrimitiveMiscCaps = D3DPMISCCAPS_CULLCCW |
1422 D3DPMISCCAPS_CULLCW |
1423 D3DPMISCCAPS_COLORWRITEENABLE |
1424 D3DPMISCCAPS_CLIPTLVERTS |
1425 D3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
1427 /*NOT: D3DPMISCCAPS_TSSARGTEMP*/
1429 *pCaps->RasterCaps = D3DPRASTERCAPS_DITHER |
1430 D3DPRASTERCAPS_PAT |
1431 D3DPRASTERCAPS_WFOG |
1432 D3DPRASTERCAPS_ZFOG |
1433 D3DPRASTERCAPS_FOGVERTEX |
1434 D3DPRASTERCAPS_FOGTABLE |
1435 D3DPRASTERCAPS_FOGRANGE;
1437 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
1438 *pCaps->RasterCaps |= D3DPRASTERCAPS_ANISOTROPY |
1439 D3DPRASTERCAPS_ZBIAS |
1440 D3DPRASTERCAPS_MIPMAPLODBIAS;
1443 D3DPRASTERCAPS_COLORPERSPECTIVE
1444 D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
1445 D3DPRASTERCAPS_ANTIALIASEDGES
1446 D3DPRASTERCAPS_ZBUFFERLESSHSR
1447 D3DPRASTERCAPS_WBUFFER */
1449 *pCaps->ZCmpCaps = D3DPCMPCAPS_ALWAYS |
1451 D3DPCMPCAPS_GREATER |
1452 D3DPCMPCAPS_GREATEREQUAL |
1454 D3DPCMPCAPS_LESSEQUAL |
1456 D3DPCMPCAPS_NOTEQUAL;
1458 *pCaps->SrcBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
1459 *pCaps->DestBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
1460 *pCaps->AlphaCmpCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
1462 *pCaps->ShadeCaps = D3DPSHADECAPS_SPECULARGOURAUDRGB |
1463 D3DPSHADECAPS_COLORGOURAUDRGB;
1465 *pCaps->TextureCaps = D3DPTEXTURECAPS_ALPHA |
1466 D3DPTEXTURECAPS_ALPHAPALETTE |
1467 D3DPTEXTURECAPS_VOLUMEMAP |
1468 D3DPTEXTURECAPS_MIPMAP |
1469 D3DPTEXTURECAPS_PROJECTED |
1470 D3DPTEXTURECAPS_PERSPECTIVE |
1471 D3DPTEXTURECAPS_VOLUMEMAP_POW2 ;
1472 /* TODO: add support for NON-POW2 if avaialble
1475 if (This->dxVersion > 8) {
1476 *pCaps->TextureCaps |= D3DPTEXTURECAPS_NONPOW2CONDITIONAL;
1478 } else { /* NONPOW2 isn't accessible by d3d8 yet */
1479 *pCaps->TextureCaps |= D3DPTEXTURECAPS_POW2;
1482 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
1483 *pCaps->TextureCaps |= D3DPTEXTURECAPS_CUBEMAP |
1484 D3DPTEXTURECAPS_MIPCUBEMAP |
1485 D3DPTEXTURECAPS_CUBEMAP_POW2;
1489 *pCaps->TextureFilterCaps = D3DPTFILTERCAPS_MAGFLINEAR |
1490 D3DPTFILTERCAPS_MAGFPOINT |
1491 D3DPTFILTERCAPS_MINFLINEAR |
1492 D3DPTFILTERCAPS_MINFPOINT |
1493 D3DPTFILTERCAPS_MIPFLINEAR |
1494 D3DPTFILTERCAPS_MIPFPOINT;
1496 *pCaps->CubeTextureFilterCaps = 0;
1497 *pCaps->VolumeTextureFilterCaps = 0;
1499 *pCaps->TextureAddressCaps = D3DPTADDRESSCAPS_BORDER |
1500 D3DPTADDRESSCAPS_CLAMP |
1501 D3DPTADDRESSCAPS_WRAP;
1503 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
1504 *pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_BORDER;
1506 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
1507 *pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRROR;
1509 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
1510 *pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
1513 *pCaps->VolumeTextureAddressCaps = 0;
1515 *pCaps->LineCaps = D3DLINECAPS_TEXTURE |
1519 D3DLINECAPS_ALPHACMP
1522 *pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
1523 *pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
1525 *pCaps->MaxVolumeExtent = 0;
1527 *pCaps->MaxTextureRepeat = 32768;
1528 *pCaps->MaxTextureAspectRatio = 32768;
1529 *pCaps->MaxVertexW = 1.0;
1531 *pCaps->GuardBandLeft = 0;
1532 *pCaps->GuardBandTop = 0;
1533 *pCaps->GuardBandRight = 0;
1534 *pCaps->GuardBandBottom = 0;
1536 *pCaps->ExtentsAdjust = 0;
1538 *pCaps->StencilCaps = D3DSTENCILCAPS_DECRSAT |
1539 D3DSTENCILCAPS_INCRSAT |
1540 D3DSTENCILCAPS_INVERT |
1541 D3DSTENCILCAPS_KEEP |
1542 D3DSTENCILCAPS_REPLACE |
1543 D3DSTENCILCAPS_ZERO;
1544 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
1545 *pCaps->StencilCaps |= D3DSTENCILCAPS_DECR |
1546 D3DSTENCILCAPS_INCR;
1549 *pCaps->FVFCaps = D3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
1551 *pCaps->TextureOpCaps = D3DTEXOPCAPS_ADD |
1552 D3DTEXOPCAPS_ADDSIGNED |
1553 D3DTEXOPCAPS_ADDSIGNED2X |
1554 D3DTEXOPCAPS_MODULATE |
1555 D3DTEXOPCAPS_MODULATE2X |
1556 D3DTEXOPCAPS_MODULATE4X |
1557 D3DTEXOPCAPS_SELECTARG1 |
1558 D3DTEXOPCAPS_SELECTARG2 |
1559 D3DTEXOPCAPS_DISABLE;
1560 #if defined(GL_VERSION_1_3)
1561 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_DOTPRODUCT3 |
1562 D3DTEXOPCAPS_SUBTRACT;
1564 if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE) ||
1565 GL_SUPPORT(EXT_TEXTURE_ENV_COMBINE) ||
1566 GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1567 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_BLENDDIFFUSEALPHA |
1568 D3DTEXOPCAPS_BLENDTEXTUREALPHA |
1569 D3DTEXOPCAPS_BLENDFACTORALPHA |
1570 D3DTEXOPCAPS_BLENDCURRENTALPHA |
1573 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1574 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_ADDSMOOTH |
1575 D3DTEXOPCAPS_MULTIPLYADD |
1576 D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
1577 D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
1578 D3DTEXOPCAPS_BLENDTEXTUREALPHAPM;
1582 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_BUMPENVMAP;
1584 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
1585 D3DTEXOPCAPS_PREMODULATE */
1588 *pCaps->MaxTextureBlendStages = GL_LIMITS(textures);
1589 *pCaps->MaxSimultaneousTextures = GL_LIMITS(textures);
1590 *pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
1591 *pCaps->MaxActiveLights = GL_LIMITS(lights);
1595 #if 0 /* TODO: Blends support in drawprim */
1596 *pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
1598 *pCaps->MaxVertexBlendMatrices = 0;
1600 *pCaps->MaxVertexBlendMatrixIndex = 1;
1602 *pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
1603 *pCaps->MaxPointSize = GL_LIMITS(pointsize);
1606 *pCaps->VertexProcessingCaps = D3DVTXPCAPS_DIRECTIONALLIGHTS |
1607 D3DVTXPCAPS_MATERIALSOURCE7 |
1608 D3DVTXPCAPS_POSITIONALLIGHTS |
1609 D3DVTXPCAPS_LOCALVIEWER |
1612 D3DVTXPCAPS_TWEENING */
1614 *pCaps->MaxPrimitiveCount = 0xFFFFFFFF;
1615 *pCaps->MaxVertexIndex = 0xFFFFFFFF;
1616 *pCaps->MaxStreams = MAX_STREAMS;
1617 *pCaps->MaxStreamStride = 1024;
1619 if (((wined3d_settings.vs_mode == VS_HW) && GL_SUPPORT(ARB_VERTEX_PROGRAM)) || (wined3d_settings.vs_mode == VS_SW) || (DeviceType == D3DDEVTYPE_REF)) {
1620 *pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
1622 if (This->gl_info.gl_vendor == VENDOR_MESA ||
1623 This->gl_info.gl_vendor == VENDOR_WINE) {
1624 *pCaps->MaxVertexShaderConst = 95;
1626 *pCaps->MaxVertexShaderConst = WINED3D_VSHADER_MAX_CONSTANTS;
1629 *pCaps->VertexShaderVersion = 0;
1630 *pCaps->MaxVertexShaderConst = 0;
1633 if ((wined3d_settings.ps_mode == PS_HW) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM) && (DeviceType != D3DDEVTYPE_REF)) {
1634 *pCaps->PixelShaderVersion = D3DPS_VERSION(1,4);
1635 *pCaps->PixelShader1xMaxValue = 1.0;
1637 *pCaps->PixelShaderVersion = 0;
1638 *pCaps->PixelShader1xMaxValue = 0.0;
1640 /* TODO: ARB_FRAGMENT_PROGRAM_100 */
1642 /* ------------------------------------------------
1643 The following fields apply to d3d9 only
1644 ------------------------------------------------ */
1645 if (This->dxVersion > 8) {
1646 GLint max_buffers = 1;
1647 FIXME("Caps support for directx9 is nonexistent at the moment!\n");
1648 *pCaps->DevCaps2 = 0;
1649 /* TODO: D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES */
1650 *pCaps->MaxNpatchTessellationLevel = 0;
1651 *pCaps->MasterAdapterOrdinal = 0;
1652 *pCaps->AdapterOrdinalInGroup = 0;
1653 *pCaps->NumberOfAdaptersInGroup = 1;
1654 *pCaps->DeclTypes = 0;
1655 #if 0 /*FIXME: Simultaneous render targets*/
1656 GL_MAX_DRAW_BUFFERS_ATI 0x00008824
1657 if (GL_SUPPORT(GL_MAX_DRAW_BUFFERS_ATI)) {
1659 glEnable(GL_MAX_DRAW_BUFFERS_ATI);
1660 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ATI, &max_buffers);
1661 glDisable(GL_MAX_DRAW_BUFFERS_ATI);
1665 *pCaps->NumSimultaneousRTs = max_buffers;
1666 *pCaps->StretchRectFilterCaps = 0;
1668 D3DPTFILTERCAPS_MINFPOINT
1669 D3DPTFILTERCAPS_MAGFPOINT
1670 D3DPTFILTERCAPS_MINFLINEAR
1671 D3DPTFILTERCAPS_MAGFLINEAR
1673 *pCaps->VS20Caps.Caps = 0;
1674 *pCaps->PS20Caps.Caps = 0;
1675 *pCaps->VertexTextureFilterCaps = 0;
1676 *pCaps->MaxVShaderInstructionsExecuted = 0;
1677 *pCaps->MaxPShaderInstructionsExecuted = 0;
1678 *pCaps->MaxVertexShader30InstructionSlots = 0;
1679 *pCaps->MaxPixelShader30InstructionSlots = 0;
1686 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
1687 and fields being inserted in the middle, a new structure is used in place */
1688 HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
1689 DWORD BehaviourFlags, WINED3DPRESENT_PARAMETERS* pPresentationParameters,
1690 IWineD3DDevice** ppReturnedDeviceInterface, IUnknown *parent,
1691 D3DCB_CREATEADDITIONALSWAPCHAIN D3DCB_CreateAdditionalSwapChain) {
1693 IWineD3DDeviceImpl *object = NULL;
1694 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1695 IWineD3DSwapChainImpl *swapchain;
1697 /* Validate the adapter number */
1698 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1699 return D3DERR_INVALIDCALL;
1702 /* Create a WineD3DDevice object */
1703 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
1704 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
1705 TRACE("Created WineD3DDevice object @ %p\n", object);
1706 if (NULL == object) {
1707 return D3DERR_OUTOFVIDEOMEMORY;
1710 /* Set up initial COM information */
1711 object->lpVtbl = &IWineD3DDevice_Vtbl;
1713 object->wineD3D = iface;
1714 IWineD3D_AddRef(object->wineD3D);
1715 object->parent = parent;
1717 /* Set the state up as invalid until the device is fully created */
1718 object->state = D3DERR_DRIVERINTERNALERROR;
1720 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %lx, PresParms: %p, RetDevInt: %p)\n", This, Adapter, DeviceType,
1721 hFocusWindow, BehaviourFlags, pPresentationParameters, ppReturnedDeviceInterface);
1722 TRACE("(%p)->(DepthStencil:(%u,%s), BackBufferFormat:(%u,%s))\n", This,
1723 *(pPresentationParameters->AutoDepthStencilFormat), debug_d3dformat(*(pPresentationParameters->AutoDepthStencilFormat)),
1724 *(pPresentationParameters->BackBufferFormat), debug_d3dformat(*(pPresentationParameters->BackBufferFormat)));
1726 /* Save the creation parameters */
1727 object->createParms.AdapterOrdinal = Adapter;
1728 object->createParms.DeviceType = DeviceType;
1729 object->createParms.hFocusWindow = hFocusWindow;
1730 object->createParms.BehaviorFlags = BehaviourFlags;
1732 /* Initialize other useful values */
1733 object->adapterNo = Adapter;
1734 object->devType = DeviceType;
1736 /* FIXME: Use for dx8 code eventually too! */
1737 /* Deliberately no indentation here, as this if will be removed when dx8 support merged in */
1738 if (This->dxVersion > 8) {
1739 TRACE("(%p) : Creating stateblock\n", This);
1740 /* Creating the startup stateBlock - Note Special Case: 0 => Don't fill in yet! */
1741 if (D3D_OK != IWineD3DDevice_CreateStateBlock((IWineD3DDevice *)object,
1743 (IWineD3DStateBlock **)&object->stateBlock,
1744 NULL) || NULL == object->stateBlock) { /* Note: No parent needed for initial internal stateblock */
1745 WARN("Failed to create stateblock\n");
1746 goto create_device_error;
1748 TRACE("(%p) : Created stateblock (%p)\n", This, object->stateBlock);
1749 object->updateStateBlock = object->stateBlock;
1750 IWineD3DStateBlock_AddRef((IWineD3DStateBlock*)object->updateStateBlock);
1751 /* Setup surfaces for the backbuffer, frontbuffer and depthstencil buffer */
1753 /* Setup some defaults for creating the implicit swapchain */
1755 IWineD3DImpl_FillGLCaps(&This->gl_info, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
1758 /* Setup the implicit swapchain */
1759 TRACE("Creating implicit swapchain\n");
1760 if (D3D_OK != D3DCB_CreateAdditionalSwapChain((IUnknown *) object->parent, pPresentationParameters, (IWineD3DSwapChain **)&swapchain) || swapchain == NULL) {
1761 WARN("Failed to create implicit swapchain\n");
1762 goto create_device_error;
1765 object->renderTarget = swapchain->backBuffer;
1766 IWineD3DSurface_AddRef(object->renderTarget);
1767 /* Depth Stencil support */
1768 object->stencilBufferTarget = object->depthStencilBuffer;
1769 if (NULL != object->stencilBufferTarget) {
1770 IWineD3DSurface_AddRef(object->stencilBufferTarget);
1773 /* Set up some starting GL setup */
1776 * Initialize openGL extension related variables
1777 * with Default values
1780 This->isGLInfoValid = IWineD3DImpl_FillGLCaps(&This->gl_info, swapchain->display);
1781 /* Setup all the devices defaults */
1782 IWineD3DStateBlock_InitStartupStateBlock((IWineD3DStateBlock *)object->stateBlock);
1784 IWineD3DImpl_CheckGraphicsMemory();
1788 { /* Set a default viewport */
1792 vp.Width = *(pPresentationParameters->BackBufferWidth);
1793 vp.Height = *(pPresentationParameters->BackBufferHeight);
1796 IWineD3DDevice_SetViewport((IWineD3DDevice *)object, &vp);
1800 /* Initialize the current view state */
1801 object->modelview_valid = 1;
1802 object->proj_valid = 0;
1803 object->view_ident = 1;
1804 object->last_was_rhw = 0;
1805 glGetIntegerv(GL_MAX_LIGHTS, &object->maxConcurrentLights);
1806 TRACE("(%p,%d) All defaults now set up, leaving CreateDevice with %p\n", This, Adapter, object);
1808 /* Clear the screen */
1809 IWineD3DDevice_Clear((IWineD3DDevice *) object, 0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET, 0x00, 1.0, 0);
1811 } else { /* End of FIXME: remove when dx8 merged in */
1813 FIXME("(%p) Incomplete stub for d3d8\n", This);
1817 /* set the state of the device to valid */
1818 object->state = D3D_OK;
1821 create_device_error:
1823 /* Set the device state to error */
1824 object->state = D3DERR_DRIVERINTERNALERROR;
1826 if (object->updateStateBlock != NULL) {
1827 IWineD3DStateBlock_Release((IWineD3DStateBlock *)object->updateStateBlock);
1828 object->updateStateBlock = NULL;
1830 if (object->stateBlock != NULL) {
1831 IWineD3DStateBlock_Release((IWineD3DStateBlock *)object->stateBlock);
1832 object->stateBlock = NULL;
1834 if (object->renderTarget != NULL) {
1835 IWineD3DSurface_Release(object->renderTarget);
1836 object->renderTarget = NULL;
1838 if (object->stencilBufferTarget != NULL) {
1839 IWineD3DSurface_Release(object->stencilBufferTarget);
1840 object->stencilBufferTarget = NULL;
1842 if (object->stencilBufferTarget != NULL) {
1843 IWineD3DSurface_Release(object->stencilBufferTarget);
1844 object->stencilBufferTarget = NULL;
1846 if (swapchain != NULL) {
1847 IWineD3DSwapChain_Release((IWineD3DSwapChain *)swapchain);
1850 HeapFree(GetProcessHeap(), 0, object);
1851 *ppReturnedDeviceInterface = NULL;
1852 return D3DERR_INVALIDCALL;
1856 HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
1857 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1858 IUnknown_AddRef(This->parent);
1859 *pParent = This->parent;
1863 /**********************************************************
1864 * IWineD3D VTbl follows
1865 **********************************************************/
1867 const IWineD3DVtbl IWineD3D_Vtbl =
1870 IWineD3DImpl_QueryInterface,
1871 IWineD3DImpl_AddRef,
1872 IWineD3DImpl_Release,
1874 IWineD3DImpl_GetParent,
1875 IWineD3DImpl_GetAdapterCount,
1876 IWineD3DImpl_RegisterSoftwareDevice,
1877 IWineD3DImpl_GetAdapterMonitor,
1878 IWineD3DImpl_GetAdapterModeCount,
1879 IWineD3DImpl_EnumAdapterModes,
1880 IWineD3DImpl_GetAdapterDisplayMode,
1881 IWineD3DImpl_GetAdapterIdentifier,
1882 IWineD3DImpl_CheckDeviceMultiSampleType,
1883 IWineD3DImpl_CheckDepthStencilMatch,
1884 IWineD3DImpl_CheckDeviceType,
1885 IWineD3DImpl_CheckDeviceFormat,
1886 IWineD3DImpl_CheckDeviceFormatConversion,
1887 IWineD3DImpl_GetDeviceCaps,
1888 IWineD3DImpl_CreateDevice