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 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created
63 * ie there is no GL Context - Get a default rendering context to enable the
64 * function query some info from GL
66 static WineD3D_Context* WineD3D_CreateFakeGLContext(void) {
67 static WineD3D_Context ctx = { NULL, NULL, NULL, 0, 0 };
68 WineD3D_Context* ret = NULL;
70 if (glXGetCurrentContext() == NULL) {
71 BOOL gotContext = FALSE;
78 XWindowAttributes win_attr;
80 TRACE_(d3d_caps)("Creating Fake GL Context\n");
82 ctx.drawable = (Drawable) GetPropA(GetDesktopWindow(), "__wine_x11_whole_window");
85 device_context = GetDC(0);
86 ctx.display = get_display(device_context);
87 ReleaseDC(0, device_context);
89 /* Get the X visual */
91 if (XGetWindowAttributes(ctx.display, ctx.drawable, &win_attr)) {
92 visual = win_attr.visual;
94 visual = DefaultVisual(ctx.display, DefaultScreen(ctx.display));
96 template.visualid = XVisualIDFromVisual(visual);
97 ctx.visInfo = XGetVisualInfo(ctx.display, VisualIDMask, &template, &num);
98 if (ctx.visInfo == NULL) {
100 WARN_(d3d_caps)("Error creating visual info for capabilities initialization\n");
104 /* Create a GL context */
106 ctx.glCtx = glXCreateContext(ctx.display, ctx.visInfo, NULL, GL_TRUE);
108 if (ctx.glCtx == NULL) {
110 WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
115 /* Make it the current GL context */
116 if (!failed && glXMakeCurrent(ctx.display, ctx.drawable, ctx.glCtx) == False) {
117 glXDestroyContext(ctx.display, ctx.glCtx);
119 WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
123 /* It worked! Wow... */
133 if (ctx.ref > 0) ret = &ctx;
136 if (NULL != ret) InterlockedIncrement(&ret->ref);
140 static void WineD3D_ReleaseFakeGLContext(WineD3D_Context* ctx) {
141 /* If we created a dummy context, throw it away */
143 if (0 == InterlockedDecrement(&ctx->ref)) {
144 glXMakeCurrent(ctx->display, None, NULL);
145 glXDestroyContext(ctx->display, ctx->glCtx);
153 /**********************************************************
154 * IUnknown parts follows
155 **********************************************************/
157 HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
159 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
160 /* FIXME: This needs to extend an IWineD3DBaseObject */
162 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
163 if (IsEqualGUID(riid, &IID_IUnknown)
164 || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
165 IUnknown_AddRef(iface);
170 return E_NOINTERFACE;
173 ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
174 IWineD3DImpl *This = (IWineD3DImpl *)iface;
175 ULONG refCount = InterlockedIncrement(&This->ref);
177 TRACE("(%p) : AddRef increasing from %ld\n", This, refCount - 1);
181 ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
182 IWineD3DImpl *This = (IWineD3DImpl *)iface;
184 TRACE("(%p) : Releasing from %ld\n", This, This->ref);
185 ref = InterlockedDecrement(&This->ref);
187 HeapFree(GetProcessHeap(), 0, This);
193 /**********************************************************
194 * IWineD3D parts follows
195 **********************************************************/
197 static BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info, Display* display) {
198 const char *GL_Extensions = NULL;
199 const char *GLX_Extensions = NULL;
200 const char *gl_string = NULL;
201 const char *gl_string_cursor = NULL;
206 WineD3D_Context *fake_ctx = NULL;
207 BOOL gotContext = FALSE;
209 /* Make sure that we've got a context */
210 if (glXGetCurrentContext() == NULL) {
211 /* TODO: CreateFakeGLContext should really take a display as a parameter */
212 fake_ctx = WineD3D_CreateFakeGLContext();
213 if (NULL != fake_ctx) gotContext = TRUE;
219 TRACE_(d3d_caps)("(%p, %p)\n", gl_info, display);
221 /* Fill in the GL info retrievable depending on the display */
222 if (NULL != display) {
223 test = glXQueryVersion(display, &major, &minor);
224 gl_info->glx_version = ((major & 0x0000FFFF) << 16) | (minor & 0x0000FFFF);
225 gl_string = glXGetClientString(display, GLX_VENDOR);
227 FIXME("Display must not be NULL, use glXGetCurrentDisplay or getAdapterDisplay()\n");
228 gl_string = glGetString(GL_VENDOR);
230 TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
231 if (gl_string != NULL) {
232 /* Fill in the GL vendor */
233 if (strstr(gl_string, "NVIDIA")) {
234 gl_info->gl_vendor = VENDOR_NVIDIA;
235 } else if (strstr(gl_string, "ATI")) {
236 gl_info->gl_vendor = VENDOR_ATI;
238 gl_info->gl_vendor = VENDOR_WINE;
241 gl_info->gl_vendor = VENDOR_WINE;
245 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
247 /* Parse the GL_VERSION field into major and minor information */
248 gl_string = glGetString(GL_VERSION);
249 if (gl_string != NULL) {
251 switch (gl_info->gl_vendor) {
253 gl_string_cursor = strstr(gl_string, "NVIDIA");
254 gl_string_cursor = strstr(gl_string_cursor, " ");
255 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
256 if (*gl_string_cursor) {
260 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
261 tmp[cursor++] = *gl_string_cursor;
267 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
270 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
271 tmp[cursor++] = *gl_string_cursor;
281 gl_string_cursor = strchr(gl_string, '-');
282 if (gl_string_cursor) {
286 /* Check if version number is of the form x.y.z */
287 if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
289 if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
291 if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
293 if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
296 /* Mark version number as malformed */
298 gl_string_cursor = 0;
301 if (!gl_string_cursor)
302 WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
304 major = *gl_string_cursor - '0';
305 minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
313 gl_info->gl_driver_version = MAKEDWORD_VERSION(major, minor);
314 TRACE_(d3d_caps)("found GL_VERSION (%s)->(0x%08lx)\n", debugstr_a(gl_string), gl_info->gl_driver_version);
316 /* Fill in the renderer information */
317 gl_string = glGetString(GL_RENDERER);
318 strcpy(gl_info->gl_renderer, gl_string);
320 switch (gl_info->gl_vendor) {
322 if (strstr(gl_info->gl_renderer, "GeForce4 Ti")) {
323 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4600;
324 } else if (strstr(gl_info->gl_renderer, "GeForceFX")) {
325 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5900ULTRA;
327 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4600;
332 if (strstr(gl_info->gl_renderer, "RADEON 9800 PRO")) {
333 gl_info->gl_card = CARD_ATI_RADEON_9800PRO;
334 } else if (strstr(gl_info->gl_renderer, "RADEON 9700 PRO")) {
335 gl_info->gl_card = CARD_ATI_RADEON_9700PRO;
337 gl_info->gl_card = CARD_ATI_RADEON_8500;
342 gl_info->gl_card = CARD_WINE;
346 FIXME("get version string returned null\n");
349 TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
352 * Initialize openGL extension related variables
353 * with Default values
355 memset(&gl_info->supported, 0, sizeof(gl_info->supported));
356 gl_info->max_textures = 1;
357 gl_info->max_samplers = 1;
358 gl_info->ps_arb_version = PS_VERSION_NOT_SUPPORTED;
359 gl_info->vs_arb_version = VS_VERSION_NOT_SUPPORTED;
360 gl_info->vs_nv_version = VS_VERSION_NOT_SUPPORTED;
361 gl_info->vs_ati_version = VS_VERSION_NOT_SUPPORTED;
363 /* Now work out what GL support this card really has */
364 #define USE_GL_FUNC(type, pfn) gl_info->pfn = NULL;
368 /* Retrieve opengl defaults */
369 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
370 gl_info->max_clipplanes = min(D3DMAXUSERCLIPPLANES, gl_max);
371 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
373 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
374 gl_info->max_lights = gl_max;
375 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
377 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
378 gl_info->max_texture_size = gl_max;
379 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
381 glGetFloatv(GL_POINT_SIZE_RANGE, &gl_float);
382 gl_info->max_pointsize = gl_float;
383 TRACE_(d3d_caps)("Maximum point size support - max texture size=%f\n", gl_float);
385 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
386 GL_Extensions = glGetString(GL_EXTENSIONS);
387 TRACE_(d3d_caps)("GL_Extensions reported:\n");
389 if (NULL == GL_Extensions) {
390 ERR(" GL_Extensions returns NULL\n");
392 while (*GL_Extensions != 0x00) {
393 const char *Start = GL_Extensions;
396 memset(ThisExtn, 0x00, sizeof(ThisExtn));
397 while (*GL_Extensions != ' ' && *GL_Extensions != 0x00) {
400 memcpy(ThisExtn, Start, (GL_Extensions - Start));
401 TRACE_(d3d_caps)("- %s\n", ThisExtn);
406 if (strcmp(ThisExtn, "GL_ARB_fragment_program") == 0) {
407 gl_info->ps_arb_version = PS_VERSION_11;
408 TRACE_(d3d_caps)(" FOUND: ARB Pixel Shader support - version=%02x\n", gl_info->ps_arb_version);
409 gl_info->supported[ARB_FRAGMENT_PROGRAM] = TRUE;
410 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &gl_max);
411 TRACE_(d3d_caps)(" FOUND: ARB Pixel Shader support - GL_MAX_TEXTURE_IMAGE_UNITS_ARB=%u\n", gl_max);
412 gl_info->max_samplers = min(MAX_SAMPLERS, gl_max);
413 } else if (strcmp(ThisExtn, "GL_ARB_multisample") == 0) {
414 TRACE_(d3d_caps)(" FOUND: ARB Multisample support\n");
415 gl_info->supported[ARB_MULTISAMPLE] = TRUE;
416 } else if (strcmp(ThisExtn, "GL_ARB_multitexture") == 0) {
417 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
418 TRACE_(d3d_caps)(" FOUND: ARB Multitexture support - GL_MAX_TEXTURE_UNITS_ARB=%u\n", gl_max);
419 gl_info->supported[ARB_MULTITEXTURE] = TRUE;
420 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
421 gl_info->max_samplers = max(gl_info->max_samplers, gl_max);
422 } else if (strcmp(ThisExtn, "GL_ARB_texture_cube_map") == 0) {
423 TRACE_(d3d_caps)(" FOUND: ARB Texture Cube Map support\n");
424 gl_info->supported[ARB_TEXTURE_CUBE_MAP] = TRUE;
425 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
426 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
427 } else if (strcmp(ThisExtn, "GL_ARB_texture_compression") == 0) {
428 TRACE_(d3d_caps)(" FOUND: ARB Texture Compression support\n");
429 gl_info->supported[ARB_TEXTURE_COMPRESSION] = TRUE;
430 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_add") == 0) {
431 TRACE_(d3d_caps)(" FOUND: ARB Texture Env Add support\n");
432 gl_info->supported[ARB_TEXTURE_ENV_ADD] = TRUE;
433 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_combine") == 0) {
434 TRACE_(d3d_caps)(" FOUND: ARB Texture Env combine support\n");
435 gl_info->supported[ARB_TEXTURE_ENV_COMBINE] = TRUE;
436 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_dot3") == 0) {
437 TRACE_(d3d_caps)(" FOUND: ARB Dot3 support\n");
438 gl_info->supported[ARB_TEXTURE_ENV_DOT3] = TRUE;
439 } else if (strcmp(ThisExtn, "GL_ARB_texture_border_clamp") == 0) {
440 TRACE_(d3d_caps)(" FOUND: ARB Texture border clamp support\n");
441 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] = TRUE;
442 } else if (strcmp(ThisExtn, "GL_ARB_texture_mirrored_repeat") == 0) {
443 TRACE_(d3d_caps)(" FOUND: ARB Texture mirrored repeat support\n");
444 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] = TRUE;
445 } else if (strcmp(ThisExtn, "GLX_ARB_multisample") == 0) {
446 TRACE_(d3d_caps)(" FOUND: ARB multisample support\n");
447 gl_info->supported[ARB_MULTISAMPLE] = TRUE;
448 } else if (strcmp(ThisExtn, "GL_ARB_point_sprite") == 0) {
449 TRACE_(d3d_caps)(" FOUND: ARB point sprint support\n");
450 gl_info->supported[ARB_POINT_SPRITE] = TRUE;
451 } else if (strstr(ThisExtn, "GL_ARB_vertex_program")) {
452 gl_info->vs_arb_version = VS_VERSION_11;
453 TRACE_(d3d_caps)(" FOUND: ARB Vertex Shader support - version=%02x\n", gl_info->vs_arb_version);
454 gl_info->supported[ARB_VERTEX_PROGRAM] = TRUE;
455 } else if (strcmp(ThisExtn, "GL_ARB_vertex_blend") == 0) {
456 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
457 TRACE_(d3d_caps)(" FOUND: ARB Vertex Blend support GL_MAX_VERTEX_UNITS_ARB %d\n", gl_max);
458 gl_info->max_blends = gl_max;
459 gl_info->supported[ARB_VERTEX_BLEND] = TRUE;
460 } else if (strcmp(ThisExtn, "GL_ARB_vertex_buffer_object") == 0) {
461 TRACE_(d3d_caps)(" FOUND: ARB Vertex Buffer support\n");
462 gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] = TRUE;
466 } else if (strcmp(ThisExtn, "GL_EXT_fog_coord") == 0) {
467 TRACE_(d3d_caps)(" FOUND: EXT Fog coord support\n");
468 gl_info->supported[EXT_FOG_COORD] = TRUE;
469 } else if (strcmp(ThisExtn, "GL_EXT_paletted_texture") == 0) { /* handle paletted texture extensions */
470 TRACE_(d3d_caps)(" FOUND: EXT Paletted texture support\n");
471 gl_info->supported[EXT_PALETTED_TEXTURE] = TRUE;
472 } else if (strcmp(ThisExtn, "GL_EXT_point_parameters") == 0) {
473 TRACE_(d3d_caps)(" FOUND: EXT Point parameters support\n");
474 gl_info->supported[EXT_POINT_PARAMETERS] = TRUE;
475 } else if (strcmp(ThisExtn, "GL_EXT_secondary_color") == 0) {
476 TRACE_(d3d_caps)(" FOUND: EXT Secondary coord support\n");
477 gl_info->supported[EXT_SECONDARY_COLOR] = TRUE;
478 } else if (strcmp(ThisExtn, "GL_EXT_stencil_wrap") == 0) {
479 TRACE_(d3d_caps)(" FOUND: EXT Stencil wrap support\n");
480 gl_info->supported[EXT_STENCIL_WRAP] = TRUE;
481 } else if (strcmp(ThisExtn, "GL_EXT_texture_compression_s3tc") == 0) {
482 TRACE_(d3d_caps)(" FOUND: EXT Texture S3TC compression support\n");
483 gl_info->supported[EXT_TEXTURE_COMPRESSION_S3TC] = TRUE;
484 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_add") == 0) {
485 TRACE_(d3d_caps)(" FOUND: EXT Texture Env Add support\n");
486 gl_info->supported[EXT_TEXTURE_ENV_ADD] = TRUE;
487 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_combine") == 0) {
488 TRACE_(d3d_caps)(" FOUND: EXT Texture Env combine support\n");
489 gl_info->supported[EXT_TEXTURE_ENV_COMBINE] = TRUE;
490 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_dot3") == 0) {
491 TRACE_(d3d_caps)(" FOUND: EXT Dot3 support\n");
492 gl_info->supported[EXT_TEXTURE_ENV_DOT3] = TRUE;
493 } else if (strcmp(ThisExtn, "GL_EXT_texture_filter_anisotropic") == 0) {
494 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] = TRUE;
495 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
496 TRACE_(d3d_caps)(" FOUND: EXT Texture Anisotropic filter support. GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT %d\n", gl_max);
497 gl_info->max_anisotropy = gl_max;
498 } else if (strcmp(ThisExtn, "GL_EXT_texture_lod") == 0) {
499 TRACE_(d3d_caps)(" FOUND: EXT Texture LOD support\n");
500 gl_info->supported[EXT_TEXTURE_LOD] = TRUE;
501 } else if (strcmp(ThisExtn, "GL_EXT_texture_lod_bias") == 0) {
502 TRACE_(d3d_caps)(" FOUND: EXT Texture LOD bias support\n");
503 gl_info->supported[EXT_TEXTURE_LOD_BIAS] = TRUE;
504 } else if (strcmp(ThisExtn, "GL_EXT_vertex_weighting") == 0) {
505 TRACE_(d3d_caps)(" FOUND: EXT Vertex weighting support\n");
506 gl_info->supported[EXT_VERTEX_WEIGHTING] = TRUE;
511 } else if (strstr(ThisExtn, "GL_NV_fog_distance")) {
512 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Fog Distance support\n");
513 gl_info->supported[NV_FOG_DISTANCE] = TRUE;
514 } else if (strstr(ThisExtn, "GL_NV_fragment_program")) {
515 gl_info->ps_nv_version = PS_VERSION_11;
516 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Pixel Shader support - version=%02x\n", gl_info->ps_nv_version);
517 } else if (strcmp(ThisExtn, "GL_NV_register_combiners") == 0) {
518 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Register combiners (1) support\n");
519 gl_info->supported[NV_REGISTER_COMBINERS] = TRUE;
520 } else if (strcmp(ThisExtn, "GL_NV_register_combiners2") == 0) {
521 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Register combiners (2) support\n");
522 gl_info->supported[NV_REGISTER_COMBINERS2] = TRUE;
523 } else if (strcmp(ThisExtn, "GL_NV_texgen_reflection") == 0) {
524 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Gen Reflection support\n");
525 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
526 } else if (strcmp(ThisExtn, "GL_NV_texture_env_combine4") == 0) {
527 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Env combine (4) support\n");
528 gl_info->supported[NV_TEXTURE_ENV_COMBINE4] = TRUE;
529 } else if (strcmp(ThisExtn, "GL_NV_texture_shader") == 0) {
530 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (1) support\n");
531 gl_info->supported[NV_TEXTURE_SHADER] = TRUE;
532 } else if (strcmp(ThisExtn, "GL_NV_texture_shader2") == 0) {
533 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (2) support\n");
534 gl_info->supported[NV_TEXTURE_SHADER2] = TRUE;
535 } else if (strcmp(ThisExtn, "GL_NV_texture_shader3") == 0) {
536 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (3) support\n");
537 gl_info->supported[NV_TEXTURE_SHADER3] = TRUE;
538 } else if (strstr(ThisExtn, "GL_NV_vertex_program")) {
539 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);
540 gl_info->vs_nv_version = max(gl_info->vs_nv_version, (0 == strcmp(ThisExtn, "GL_NV_vertex_program2")) ? VS_VERSION_20 : VS_VERSION_10);
541 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Vertex Shader support - version=%02x\n", gl_info->vs_nv_version);
542 gl_info->supported[NV_VERTEX_PROGRAM] = TRUE;
548 } else if (strcmp(ThisExtn, "GL_ATI_texture_env_combine3") == 0) {
549 TRACE_(d3d_caps)(" FOUND: ATI Texture Env combine (3) support\n");
550 gl_info->supported[ATI_TEXTURE_ENV_COMBINE3] = TRUE;
551 } else if (strcmp(ThisExtn, "GL_ATI_texture_mirror_once") == 0) {
552 TRACE_(d3d_caps)(" FOUND: ATI Texture Mirror Once support\n");
553 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] = TRUE;
554 } else if (strcmp(ThisExtn, "GL_EXT_vertex_shader") == 0) {
555 gl_info->vs_ati_version = VS_VERSION_11;
556 TRACE_(d3d_caps)(" FOUND: ATI (EXT) Vertex Shader support - version=%02x\n", gl_info->vs_ati_version);
557 gl_info->supported[EXT_VERTEX_SHADER] = TRUE;
561 if (*GL_Extensions == ' ') GL_Extensions++;
565 #define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) glXGetProcAddressARB( (const GLubyte *) #pfn);
569 if (display != NULL) {
570 GLX_Extensions = glXQueryExtensionsString(display, DefaultScreen(display));
571 TRACE_(d3d_caps)("GLX_Extensions reported:\n");
573 if (NULL == GLX_Extensions) {
574 ERR(" GLX_Extensions returns NULL\n");
576 while (*GLX_Extensions != 0x00) {
577 const char *Start = GLX_Extensions;
580 memset(ThisExtn, 0x00, sizeof(ThisExtn));
581 while (*GLX_Extensions != ' ' && *GLX_Extensions != 0x00) {
584 memcpy(ThisExtn, Start, (GLX_Extensions - Start));
585 TRACE_(d3d_caps)("- %s\n", ThisExtn);
586 if (*GLX_Extensions == ' ') GLX_Extensions++;
591 #define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) glXGetProcAddressARB( (const GLubyte *) #pfn);
595 /* If we created a dummy context, throw it away */
596 if (NULL != fake_ctx) WineD3D_ReleaseFakeGLContext(fake_ctx);
598 /* Only save the values obtained when a display is provided */
599 if (fake_ctx == NULL) {
606 /**********************************************************
607 * IWineD3D implementation follows
608 **********************************************************/
610 UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
611 IWineD3DImpl *This = (IWineD3DImpl *)iface;
613 /* FIXME: Set to one for now to imply the display */
614 TRACE_(d3d_caps)("(%p): Mostly stub, only returns primary display\n", This);
618 HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
619 IWineD3DImpl *This = (IWineD3DImpl *)iface;
620 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
624 HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
625 IWineD3DImpl *This = (IWineD3DImpl *)iface;
626 FIXME_(d3d_caps)("(%p)->(Adptr:%d)\n", This, Adapter);
627 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
633 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
634 of the same bpp but different resolutions */
636 /* Note: dx9 supplies a format. Calls from d3d8 supply D3DFMT_UNKNOWN */
637 UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
638 IWineD3DImpl *This = (IWineD3DImpl *)iface;
639 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
641 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
645 if (Adapter == 0) { /* Display */
648 #if !defined( DEBUG_SINGLE_MODE )
651 /* Work out the current screen bpp */
652 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
653 int bpp = GetDeviceCaps(hdc, BITSPIXEL);
656 while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
663 case D3DFMT_X8R8G8B8:
664 case D3DFMT_A8R8G8B8:
665 if (min(DevModeW.dmBitsPerPel, bpp) == 32) i++;
666 if (min(DevModeW.dmBitsPerPel, bpp) == 24) i++;
668 case D3DFMT_X1R5G5B5:
669 case D3DFMT_A1R5G5B5:
671 if (min(DevModeW.dmBitsPerPel, bpp) == 16) i++;
674 /* Skip other modes as they do not match requested format */
682 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
685 FIXME_(d3d_caps)("Adapter not primary display\n");
690 /* Note: dx9 supplies a format. Calls from d3d8 supply D3DFMT_UNKNOWN */
691 HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) {
692 IWineD3DImpl *This = (IWineD3DImpl *)iface;
693 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
695 /* Validate the parameters as much as possible */
697 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
698 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
699 return D3DERR_INVALIDCALL;
702 if (Adapter == 0) { /* Display */
703 #if !defined( DEBUG_SINGLE_MODE )
707 /* Work out the current screen bpp */
708 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
709 int bpp = GetDeviceCaps(hdc, BITSPIXEL);
712 /* If we are filtering to a specific format, then need to skip all unrelated
713 modes, but if mode is irrelevant, then we can use the index directly */
714 if (Format == D3DFMT_UNKNOWN)
720 DEVMODEW DevModeWtmp;
723 while (i<(Mode+1) && EnumDisplaySettingsExW(NULL, j, &DevModeWtmp, 0)) {
730 case D3DFMT_X8R8G8B8:
731 case D3DFMT_A8R8G8B8:
732 if (min(DevModeWtmp.dmBitsPerPel, bpp) == 32) i++;
733 if (min(DevModeWtmp.dmBitsPerPel, bpp) == 24) i++;
735 case D3DFMT_X1R5G5B5:
736 case D3DFMT_A1R5G5B5:
738 if (min(DevModeWtmp.dmBitsPerPel, bpp) == 16) i++;
741 /* Skip other modes as they do not match requested format */
748 /* Now get the display mode via the calculated index */
749 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0))
751 pMode->Width = DevModeW.dmPelsWidth;
752 pMode->Height = DevModeW.dmPelsHeight;
753 bpp = min(DevModeW.dmBitsPerPel, bpp);
754 pMode->RefreshRate = D3DADAPTER_DEFAULT;
755 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
757 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
760 if (Format == D3DFMT_UNKNOWN)
763 case 8: pMode->Format = D3DFMT_R3G3B2; break;
764 case 16: pMode->Format = D3DFMT_R5G6B5; break;
765 case 24: /* pMode->Format = D3DFMT_R5G6B5; break;*/ /* Make 24bit appear as 32 bit */
766 case 32: pMode->Format = D3DFMT_A8R8G8B8; break;
767 default: pMode->Format = D3DFMT_UNKNOWN;
770 pMode->Format = Format;
775 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
776 return D3DERR_INVALIDCALL;
780 /* Return one setting of the format requested */
781 if (Mode > 0) return D3DERR_INVALIDCALL;
784 pMode->RefreshRate = D3DADAPTER_DEFAULT;
785 pMode->Format = (Format == D3DFMT_UNKNOWN) ? D3DFMT_A8R8G8B8 : Format;
788 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
789 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format), bpp);
792 FIXME_(d3d_caps)("Adapter not primary display\n");
798 HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
799 IWineD3DImpl *This = (IWineD3DImpl *)iface;
800 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
803 Adapter >= IWineD3D_GetAdapterCount(iface)) {
804 return D3DERR_INVALIDCALL;
807 if (Adapter == 0) { /* Display */
811 EnumDisplaySettingsExW(NULL, (DWORD)-1, &DevModeW, 0);
812 pMode->Width = DevModeW.dmPelsWidth;
813 pMode->Height = DevModeW.dmPelsHeight;
814 bpp = DevModeW.dmBitsPerPel;
815 pMode->RefreshRate = D3DADAPTER_DEFAULT;
816 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
818 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
822 case 8: pMode->Format = D3DFMT_R3G3B2; break;
823 case 16: pMode->Format = D3DFMT_R5G6B5; break;
824 case 24: pMode->Format = D3DFMT_X8R8G8B8; break; /* Robots needs 24bit to be X8R8G8B8 */
825 case 32: pMode->Format = D3DFMT_A8R8G8B8; break;
826 default: pMode->Format = D3DFMT_UNKNOWN;
830 FIXME_(d3d_caps)("Adapter not primary display\n");
833 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
834 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
838 static Display * WINAPI IWineD3DImpl_GetAdapterDisplay(IWineD3D *iface, UINT Adapter) {
841 /* only works with one adapter at the moment... */
843 /* Get the display */
844 device_context = GetDC(0);
845 display = get_display(device_context);
846 ReleaseDC(0, device_context);
850 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
851 and fields being inserted in the middle, a new structure is used in place */
852 HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
853 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
854 IWineD3DImpl *This = (IWineD3DImpl *)iface;
856 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %lx, pId=%p)\n", This, Adapter, Flags, pIdentifier);
858 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
859 return D3DERR_INVALIDCALL;
862 if (Adapter == 0) { /* Display - only device supported for now */
864 BOOL isGLInfoValid = This->isGLInfoValid;
866 /* FillGLCaps updates gl_info, but we only want to store and
867 reuse the values once we have a context which is valid. Values from
868 a temporary context may differ from the final ones */
869 if (isGLInfoValid == FALSE) {
870 /* If we don't know the device settings, go query them now */
871 isGLInfoValid = IWineD3DImpl_FillGLCaps(&This->gl_info, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
874 /* If it worked, return the information requested */
876 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
877 strcpy(pIdentifier->Driver, "Display");
878 strcpy(pIdentifier->Description, "Direct3D HAL");
880 /* Note dx8 doesn't supply a DeviceName */
881 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
882 pIdentifier->DriverVersion->u.HighPart = 0xa;
883 pIdentifier->DriverVersion->u.LowPart = This->gl_info.gl_driver_version;
884 *(pIdentifier->VendorId) = This->gl_info.gl_vendor;
885 *(pIdentifier->DeviceId) = This->gl_info.gl_card;
886 *(pIdentifier->SubSysId) = 0;
887 *(pIdentifier->Revision) = 0;
891 /* If it failed, return dummy values from an NVidia driver */
892 WARN_(d3d_caps)("Cannot get GLCaps for device/Vendor Name and Version detection using FillGLCaps, currently using NVIDIA identifiers\n");
893 strcpy(pIdentifier->Driver, "Display");
894 strcpy(pIdentifier->Description, "Direct3D HAL");
895 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
896 pIdentifier->DriverVersion->u.HighPart = 0xa;
897 pIdentifier->DriverVersion->u.LowPart = MAKEDWORD_VERSION(53, 96); /* last Linux Nvidia drivers */
898 *(pIdentifier->VendorId) = VENDOR_NVIDIA;
899 *(pIdentifier->DeviceId) = CARD_NVIDIA_GEFORCE4_TI4600;
900 *(pIdentifier->SubSysId) = 0;
901 *(pIdentifier->Revision) = 0;
904 /*FIXME: memcpy(&pIdentifier->DeviceIdentifier, ??, sizeof(??GUID)); */
905 if (Flags & D3DENUM_NO_WHQL_LEVEL) {
906 *(pIdentifier->WHQLLevel) = 0;
908 *(pIdentifier->WHQLLevel) = 1;
912 FIXME_(d3d_caps)("Adapter not primary display\n");
918 static BOOL IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(WineD3D_Context* ctx, GLXFBConfig cfgs, WINED3DFORMAT Format) {
920 int rb, gb, bb, ab, type, buf_sz;
922 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_RED_SIZE, &rb);
923 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_GREEN_SIZE, &gb);
924 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_BLUE_SIZE, &bb);
925 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_ALPHA_SIZE, &ab);
926 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_RENDER_TYPE, &type);
927 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_BUFFER_SIZE, &buf_sz);
930 case WINED3DFMT_X8R8G8B8:
931 case WINED3DFMT_R8G8B8:
932 if (8 == rb && 8 == gb && 8 == bb) return TRUE;
934 case WINED3DFMT_A8R8G8B8:
935 if (8 == rb && 8 == gb && 8 == bb && 8 == ab) return TRUE;
937 case WINED3DFMT_X1R5G5B5:
938 if (5 == rb && 5 == gb && 5 == bb) return TRUE;
940 case WINED3DFMT_A1R5G5B5:
941 if (5 == rb && 5 == gb && 5 == bb && 1 == ab) return TRUE;
943 case WINED3DFMT_R5G6B5:
944 if (5 == rb && 6 == gb && 5 == bb) return TRUE;
946 case WINED3DFMT_R3G3B2:
947 if (3 == rb && 3 == gb && 2 == bb) return TRUE;
949 case WINED3DFMT_A8P8:
950 if (type & GLX_COLOR_INDEX_BIT && 8 == buf_sz && 8 == ab) return TRUE;
953 if (type & GLX_COLOR_INDEX_BIT && 8 == buf_sz) return TRUE;
956 ERR("unsupported format %s\n", debug_d3dformat(Format));
962 static BOOL IWineD3DImpl_IsGLXFBConfigCompatibleWithDepthFmt(WineD3D_Context* ctx, GLXFBConfig cfgs, WINED3DFORMAT Format) {
966 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_DEPTH_SIZE, &db);
967 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_STENCIL_SIZE, &sb);
971 case WINED3DFMT_D16_LOCKABLE:
972 if (16 == db) return TRUE;
975 if (32 == db) return TRUE;
977 case WINED3DFMT_D15S1:
978 if (15 == db) return TRUE;
980 case WINED3DFMT_D24S8:
981 if (24 == db && 8 == sb) return TRUE;
983 case WINED3DFMT_D24X8:
984 if (24 == db) return TRUE;
986 case WINED3DFMT_D24X4S4:
987 if (24 == db && 4 == sb) return TRUE;
989 case WINED3DFMT_D32F_LOCKABLE:
990 if (32 == db) return TRUE;
993 ERR("unsupported format %s\n", debug_d3dformat(Format));
999 HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1000 WINED3DFORMAT AdapterFormat,
1001 WINED3DFORMAT RenderTargetFormat,
1002 WINED3DFORMAT DepthStencilFormat) {
1003 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1004 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
1006 DeviceType, debug_d3ddevicetype(DeviceType),
1007 AdapterFormat, debug_d3dformat(AdapterFormat),
1008 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
1009 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
1011 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1012 return D3DERR_INVALIDCALL;
1016 GLXFBConfig* cfgs = NULL;
1019 HRESULT hr = D3DERR_NOTAVAILABLE;
1021 WineD3D_Context* ctx = WineD3D_CreateFakeGLContext();
1023 cfgs = glXGetFBConfigs(ctx->display, DefaultScreen(ctx->display), &nCfgs);
1024 for (it = 0; it < nCfgs; ++it) {
1025 if (IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(ctx, cfgs[it], RenderTargetFormat)) {
1026 if (IWineD3DImpl_IsGLXFBConfigCompatibleWithDepthFmt(ctx, cfgs[it], DepthStencilFormat)) {
1034 WineD3D_ReleaseFakeGLContext(ctx);
1039 return D3DERR_NOTAVAILABLE;
1042 HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1043 WINED3DFORMAT SurfaceFormat,
1044 BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
1046 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1047 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
1050 DeviceType, debug_d3ddevicetype(DeviceType),
1051 SurfaceFormat, debug_d3dformat(SurfaceFormat),
1056 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1057 return D3DERR_INVALIDCALL;
1060 if (pQualityLevels != NULL) {
1061 static int s_single_shot = 0;
1062 if (!s_single_shot) {
1063 FIXME("Quality levels unsupported at present\n");
1066 *pQualityLevels = 1; /* Guess at a value! */
1069 if (D3DMULTISAMPLE_NONE == MultiSampleType) return D3D_OK;
1070 return D3DERR_NOTAVAILABLE;
1073 HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, D3DDEVTYPE CheckType,
1074 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
1076 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1077 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
1080 CheckType, debug_d3ddevicetype(CheckType),
1081 DisplayFormat, debug_d3dformat(DisplayFormat),
1082 BackBufferFormat, debug_d3dformat(BackBufferFormat),
1085 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1086 return D3DERR_INVALIDCALL;
1090 GLXFBConfig* cfgs = NULL;
1093 HRESULT hr = D3DERR_NOTAVAILABLE;
1095 WineD3D_Context* ctx = WineD3D_CreateFakeGLContext();
1097 cfgs = glXGetFBConfigs(ctx->display, DefaultScreen(ctx->display), &nCfgs);
1098 for (it = 0; it < nCfgs; ++it) {
1099 if (IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(ctx, cfgs[it], DisplayFormat)) {
1106 WineD3D_ReleaseFakeGLContext(ctx);
1111 return D3DERR_NOTAVAILABLE;
1114 HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1115 WINED3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat) {
1116 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1117 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%lu,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s)) ",
1120 DeviceType, debug_d3ddevicetype(DeviceType),
1121 AdapterFormat, debug_d3dformat(AdapterFormat),
1122 Usage, debug_d3dusage(Usage),
1123 RType, debug_d3dresourcetype(RType),
1124 CheckFormat, debug_d3dformat(CheckFormat));
1126 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1127 return D3DERR_INVALIDCALL;
1130 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1131 switch (CheckFormat) {
1135 TRACE_(d3d_caps)("[OK]\n");
1138 break; /* Avoid compiler warnings */
1142 switch (CheckFormat) {
1144 * check supported using GL_SUPPORT
1155 /*case D3DFMT_R5G6B5: */
1156 /*case D3DFMT_X1R5G5B5:*/
1157 /*case D3DFMT_A1R5G5B5: */
1158 /*case D3DFMT_A4R4G4B4:*/
1165 /*case D3DFMT_X8R8G8B8:*/
1166 case D3DFMT_A8R3G3B2:
1183 case D3DFMT_X8L8V8U8:
1184 case D3DFMT_Q8W8V8U8:
1185 case D3DFMT_W11V11U10:
1188 * currently hard to support
1193 /* Since we do not support these formats right now, don't pretend to. */
1194 TRACE_(d3d_caps)("[FAILED]\n");
1195 return D3DERR_NOTAVAILABLE;
1200 TRACE_(d3d_caps)("[OK]\n");
1204 HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1205 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
1206 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1208 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))",
1211 DeviceType, debug_d3ddevicetype(DeviceType),
1212 SourceFormat, debug_d3dformat(SourceFormat),
1213 TargetFormat, debug_d3dformat(TargetFormat));
1217 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
1218 subset of a D3DCAPS9 structure. However, it has to come via a void *
1219 as the d3d8 interface cannot import the d3d9 header */
1220 HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
1222 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1224 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
1226 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1227 return D3DERR_INVALIDCALL;
1230 /* If we don't know the device settings, go query them now */
1231 if (This->isGLInfoValid == FALSE) {
1232 /* use the desktop window to fill gl caps */
1233 BOOL rc = IWineD3DImpl_FillGLCaps(&This->gl_info, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
1235 /* We are running off a real context, save the values */
1236 if (rc) This->isGLInfoValid = TRUE;
1240 /* ------------------------------------------------
1241 The following fields apply to both d3d8 and d3d9
1242 ------------------------------------------------ */
1243 *pCaps->DeviceType = (DeviceType == D3DDEVTYPE_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
1244 *pCaps->AdapterOrdinal = Adapter;
1247 *pCaps->Caps2 = D3DCAPS2_CANRENDERWINDOWED;
1248 *pCaps->Caps3 = D3DDEVCAPS_HWTRANSFORMANDLIGHT;
1249 *pCaps->PresentationIntervals = D3DPRESENT_INTERVAL_IMMEDIATE;
1251 *pCaps->CursorCaps = 0;
1254 *pCaps->DevCaps = D3DDEVCAPS_DRAWPRIMTLVERTEX |
1255 D3DDEVCAPS_HWTRANSFORMANDLIGHT |
1256 D3DDEVCAPS_PUREDEVICE |
1257 D3DDEVCAPS_HWRASTERIZATION;
1260 *pCaps->PrimitiveMiscCaps = D3DPMISCCAPS_CULLCCW |
1261 D3DPMISCCAPS_CULLCW |
1262 D3DPMISCCAPS_COLORWRITEENABLE |
1263 D3DPMISCCAPS_CLIPTLVERTS |
1264 D3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
1266 /*NOT: D3DPMISCCAPS_TSSARGTEMP*/
1268 *pCaps->RasterCaps = D3DPRASTERCAPS_DITHER |
1269 D3DPRASTERCAPS_PAT |
1270 D3DPRASTERCAPS_WFOG |
1271 D3DPRASTERCAPS_ZFOG |
1272 D3DPRASTERCAPS_FOGVERTEX |
1273 D3DPRASTERCAPS_FOGTABLE |
1274 D3DPRASTERCAPS_FOGRANGE;
1276 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
1277 *pCaps->RasterCaps |= D3DPRASTERCAPS_ANISOTROPY |
1278 D3DPRASTERCAPS_ZBIAS |
1279 D3DPRASTERCAPS_MIPMAPLODBIAS;
1282 D3DPRASTERCAPS_COLORPERSPECTIVE
1283 D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
1284 D3DPRASTERCAPS_ANTIALIASEDGES
1285 D3DPRASTERCAPS_ZBUFFERLESSHSR
1286 D3DPRASTERCAPS_WBUFFER */
1288 *pCaps->ZCmpCaps = D3DPCMPCAPS_ALWAYS |
1290 D3DPCMPCAPS_GREATER |
1291 D3DPCMPCAPS_GREATEREQUAL |
1293 D3DPCMPCAPS_LESSEQUAL |
1295 D3DPCMPCAPS_NOTEQUAL;
1297 *pCaps->SrcBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
1298 *pCaps->DestBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
1299 *pCaps->AlphaCmpCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
1301 *pCaps->ShadeCaps = D3DPSHADECAPS_SPECULARGOURAUDRGB |
1302 D3DPSHADECAPS_COLORGOURAUDRGB;
1304 *pCaps->TextureCaps = D3DPTEXTURECAPS_ALPHA |
1305 D3DPTEXTURECAPS_ALPHAPALETTE |
1306 D3DPTEXTURECAPS_VOLUMEMAP |
1307 D3DPTEXTURECAPS_MIPMAP |
1308 D3DPTEXTURECAPS_PROJECTED |
1309 D3DPTEXTURECAPS_PERSPECTIVE |
1310 D3DPTEXTURECAPS_VOLUMEMAP_POW2 ;
1311 /* TODO: add support for NON-POW2 if avaialble
1314 if (This->dxVersion > 8) {
1315 *pCaps->TextureCaps |= D3DPTEXTURECAPS_NONPOW2CONDITIONAL;
1317 } else { /* NONPOW2 isn't accessible by d3d8 yet */
1318 *pCaps->TextureCaps |= D3DPTEXTURECAPS_POW2;
1321 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
1322 *pCaps->TextureCaps |= D3DPTEXTURECAPS_CUBEMAP |
1323 D3DPTEXTURECAPS_MIPCUBEMAP |
1324 D3DPTEXTURECAPS_CUBEMAP_POW2;
1328 *pCaps->TextureFilterCaps = D3DPTFILTERCAPS_MAGFLINEAR |
1329 D3DPTFILTERCAPS_MAGFPOINT |
1330 D3DPTFILTERCAPS_MINFLINEAR |
1331 D3DPTFILTERCAPS_MINFPOINT |
1332 D3DPTFILTERCAPS_MIPFLINEAR |
1333 D3DPTFILTERCAPS_MIPFPOINT;
1335 *pCaps->CubeTextureFilterCaps = 0;
1336 *pCaps->VolumeTextureFilterCaps = 0;
1338 *pCaps->TextureAddressCaps = D3DPTADDRESSCAPS_BORDER |
1339 D3DPTADDRESSCAPS_CLAMP |
1340 D3DPTADDRESSCAPS_WRAP;
1342 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
1343 *pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_BORDER;
1345 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
1346 *pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRROR;
1348 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
1349 *pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
1352 *pCaps->VolumeTextureAddressCaps = 0;
1354 *pCaps->LineCaps = D3DLINECAPS_TEXTURE |
1358 D3DLINECAPS_ALPHACMP
1361 *pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
1362 *pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
1364 *pCaps->MaxVolumeExtent = 0;
1366 *pCaps->MaxTextureRepeat = 32768;
1367 *pCaps->MaxTextureAspectRatio = 32768;
1368 *pCaps->MaxVertexW = 1.0;
1370 *pCaps->GuardBandLeft = 0;
1371 *pCaps->GuardBandTop = 0;
1372 *pCaps->GuardBandRight = 0;
1373 *pCaps->GuardBandBottom = 0;
1375 *pCaps->ExtentsAdjust = 0;
1377 *pCaps->StencilCaps = D3DSTENCILCAPS_DECRSAT |
1378 D3DSTENCILCAPS_INCRSAT |
1379 D3DSTENCILCAPS_INVERT |
1380 D3DSTENCILCAPS_KEEP |
1381 D3DSTENCILCAPS_REPLACE |
1382 D3DSTENCILCAPS_ZERO;
1383 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
1384 *pCaps->StencilCaps |= D3DSTENCILCAPS_DECR |
1385 D3DSTENCILCAPS_INCR;
1388 *pCaps->FVFCaps = D3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
1390 *pCaps->TextureOpCaps = D3DTEXOPCAPS_ADD |
1391 D3DTEXOPCAPS_ADDSIGNED |
1392 D3DTEXOPCAPS_ADDSIGNED2X |
1393 D3DTEXOPCAPS_MODULATE |
1394 D3DTEXOPCAPS_MODULATE2X |
1395 D3DTEXOPCAPS_MODULATE4X |
1396 D3DTEXOPCAPS_SELECTARG1 |
1397 D3DTEXOPCAPS_SELECTARG2 |
1398 D3DTEXOPCAPS_DISABLE;
1399 #if defined(GL_VERSION_1_3)
1400 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_DOTPRODUCT3 |
1401 D3DTEXOPCAPS_SUBTRACT;
1403 if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE) ||
1404 GL_SUPPORT(EXT_TEXTURE_ENV_COMBINE) ||
1405 GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1406 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_BLENDDIFFUSEALPHA |
1407 D3DTEXOPCAPS_BLENDTEXTUREALPHA |
1408 D3DTEXOPCAPS_BLENDFACTORALPHA |
1409 D3DTEXOPCAPS_BLENDCURRENTALPHA |
1412 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1413 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_ADDSMOOTH |
1414 D3DTEXOPCAPS_MULTIPLYADD |
1415 D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
1416 D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
1417 D3DTEXOPCAPS_BLENDTEXTUREALPHAPM;
1421 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_BUMPENVMAP;
1423 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
1424 D3DTEXOPCAPS_PREMODULATE */
1427 *pCaps->MaxTextureBlendStages = GL_LIMITS(textures);
1428 *pCaps->MaxSimultaneousTextures = GL_LIMITS(textures);
1429 *pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
1430 *pCaps->MaxActiveLights = GL_LIMITS(lights);
1434 #if 0 /* TODO: Blends support in drawprim */
1435 *pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
1437 *pCaps->MaxVertexBlendMatrices = 0;
1439 *pCaps->MaxVertexBlendMatrixIndex = 1;
1441 *pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
1442 *pCaps->MaxPointSize = GL_LIMITS(pointsize);
1445 *pCaps->VertexProcessingCaps = D3DVTXPCAPS_DIRECTIONALLIGHTS |
1446 D3DVTXPCAPS_MATERIALSOURCE7 |
1447 D3DVTXPCAPS_POSITIONALLIGHTS |
1448 D3DVTXPCAPS_LOCALVIEWER |
1451 D3DVTXPCAPS_TWEENING */
1453 *pCaps->MaxPrimitiveCount = 0xFFFFFFFF;
1454 *pCaps->MaxVertexIndex = 0xFFFFFFFF;
1455 *pCaps->MaxStreams = MAX_STREAMS;
1456 *pCaps->MaxStreamStride = 1024;
1458 if (((wined3d_settings.vs_mode == VS_HW) && GL_SUPPORT(ARB_VERTEX_PROGRAM)) || (wined3d_settings.vs_mode == VS_SW) || (DeviceType == D3DDEVTYPE_REF)) {
1459 *pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
1461 if (This->gl_info.gl_vendor == VENDOR_MESA ||
1462 This->gl_info.gl_vendor == VENDOR_WINE) {
1463 *pCaps->MaxVertexShaderConst = 95;
1465 *pCaps->MaxVertexShaderConst = WINED3D_VSHADER_MAX_CONSTANTS;
1468 *pCaps->VertexShaderVersion = 0;
1469 *pCaps->MaxVertexShaderConst = 0;
1472 if ((wined3d_settings.ps_mode == PS_HW) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM) && (DeviceType != D3DDEVTYPE_REF)) {
1473 *pCaps->PixelShaderVersion = D3DPS_VERSION(1,4);
1474 *pCaps->PixelShader1xMaxValue = 1.0;
1476 *pCaps->PixelShaderVersion = 0;
1477 *pCaps->PixelShader1xMaxValue = 0.0;
1479 /* TODO: ARB_FRAGMENT_PROGRAM_100 */
1481 /* ------------------------------------------------
1482 The following fields apply to d3d9 only
1483 ------------------------------------------------ */
1484 if (This->dxVersion > 8) {
1485 GLint max_buffers = 1;
1486 FIXME("Caps support for directx9 is nonexistent at the moment!\n");
1487 *pCaps->DevCaps2 = 0;
1488 /* TODO: D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES */
1489 *pCaps->MaxNpatchTessellationLevel = 0;
1490 *pCaps->MasterAdapterOrdinal = 0;
1491 *pCaps->AdapterOrdinalInGroup = 0;
1492 *pCaps->NumberOfAdaptersInGroup = 1;
1493 *pCaps->DeclTypes = 0;
1494 #if 0 /*FIXME: Simultaneous render targets*/
1495 GL_MAX_DRAW_BUFFERS_ATI 0x00008824
1496 if (GL_SUPPORT(GL_MAX_DRAW_BUFFERS_ATI)) {
1498 glEnable(GL_MAX_DRAW_BUFFERS_ATI);
1499 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ATI, &max_buffers);
1500 glDisable(GL_MAX_DRAW_BUFFERS_ATI);
1504 *pCaps->NumSimultaneousRTs = max_buffers;
1505 *pCaps->StretchRectFilterCaps = 0;
1507 D3DPTFILTERCAPS_MINFPOINT
1508 D3DPTFILTERCAPS_MAGFPOINT
1509 D3DPTFILTERCAPS_MINFLINEAR
1510 D3DPTFILTERCAPS_MAGFLINEAR
1512 *pCaps->VS20Caps.Caps = 0;
1513 *pCaps->PS20Caps.Caps = 0;
1514 *pCaps->VertexTextureFilterCaps = 0;
1515 *pCaps->MaxVShaderInstructionsExecuted = 0;
1516 *pCaps->MaxPShaderInstructionsExecuted = 0;
1517 *pCaps->MaxVertexShader30InstructionSlots = 0;
1518 *pCaps->MaxPixelShader30InstructionSlots = 0;
1525 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
1526 and fields being inserted in the middle, a new structure is used in place */
1527 HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
1528 DWORD BehaviourFlags, WINED3DPRESENT_PARAMETERS* pPresentationParameters,
1529 IWineD3DDevice** ppReturnedDeviceInterface, IUnknown *parent,
1530 D3DCB_CREATEADDITIONALSWAPCHAIN D3DCB_CreateAdditionalSwapChain) {
1532 IWineD3DDeviceImpl *object = NULL;
1533 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1534 IWineD3DSwapChainImpl *swapchain;
1536 /* Validate the adapter number */
1537 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1538 return D3DERR_INVALIDCALL;
1541 /* Create a WineD3DDevice object */
1542 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
1543 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
1544 TRACE("Created WineD3DDevice object @ %p \n", object);
1545 if (NULL == object) {
1546 return D3DERR_OUTOFVIDEOMEMORY;
1549 /* Set up initial COM information */
1550 object->lpVtbl = &IWineD3DDevice_Vtbl;
1552 object->wineD3D = iface;
1553 IWineD3D_AddRef(object->wineD3D);
1554 object->parent = parent;
1556 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %lx, PresParms: %p, RetDevInt: %p)\n", This, Adapter, DeviceType,
1557 hFocusWindow, BehaviourFlags, pPresentationParameters, ppReturnedDeviceInterface);
1558 TRACE("(%p)->(DepthStencil:(%u,%s), BackBufferFormat:(%u,%s))\n", This,
1559 *(pPresentationParameters->AutoDepthStencilFormat), debug_d3dformat(*(pPresentationParameters->AutoDepthStencilFormat)),
1560 *(pPresentationParameters->BackBufferFormat), debug_d3dformat(*(pPresentationParameters->BackBufferFormat)));
1562 /* Save the creation parameters */
1563 object->createParms.AdapterOrdinal = Adapter;
1564 object->createParms.DeviceType = DeviceType;
1565 object->createParms.hFocusWindow = hFocusWindow;
1566 object->createParms.BehaviorFlags = BehaviourFlags;
1568 /* Initialize other useful values */
1569 object->adapterNo = Adapter;
1570 object->devType = DeviceType;
1572 /* FIXME: Use for dx8 code eventually too! */
1573 /* Deliberately no indentation here, as this if will be removed when dx8 support merged in */
1574 if (This->dxVersion > 8) {
1575 TRACE("(%p) : Creating stateblock\n", This);
1576 /* Creating the startup stateBlock - Note Special Case: 0 => Don't fill in yet! */
1577 if (D3D_OK != IWineD3DDevice_CreateStateBlock((IWineD3DDevice *)object,
1579 (IWineD3DStateBlock **)&object->stateBlock,
1580 NULL) || NULL == object->stateBlock) { /* Note: No parent needed for initial internal stateblock */
1581 WARN("Failed to create stateblock\n");
1582 goto create_device_error;
1584 TRACE("(%p) : Created stateblock (%p) \n", This, object->stateBlock);
1585 object->updateStateBlock = object->stateBlock;
1586 IWineD3DStateBlock_AddRef((IWineD3DStateBlock*)object->updateStateBlock);
1587 /* Setup surfaces for the backbuffer, frontbuffer and depthstencil buffer */
1589 /* Setup some defaults for creating the implicite swapchain */
1591 IWineD3DImpl_FillGLCaps(&This->gl_info, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
1594 /* Setup the implicit swapchain */
1595 TRACE("Creating implicit swapchain\n");
1596 if (D3D_OK != D3DCB_CreateAdditionalSwapChain((IUnknown *) object->parent, pPresentationParameters, (IWineD3DSwapChain **)&swapchain) || swapchain == NULL) {
1597 WARN("Failed to create implicite swapchain\n");
1598 goto create_device_error;
1601 object->renderTarget = swapchain->backBuffer;
1602 IWineD3DSurface_AddRef(object->renderTarget);
1603 /* Depth Stencil support */
1604 object->stencilBufferTarget = object->depthStencilBuffer;
1605 if (NULL != object->stencilBufferTarget) {
1606 IWineD3DSurface_AddRef(object->stencilBufferTarget);
1609 /* Set up some starting GL setup */
1612 * Initialize openGL extension related variables
1613 * with Default values
1616 This->isGLInfoValid = IWineD3DImpl_FillGLCaps(&This->gl_info, swapchain->display);
1617 /* Setup all the devices defaults */
1618 IWineD3DStateBlock_InitStartupStateBlock((IWineD3DStateBlock *)object->stateBlock);
1620 IWineD3DImpl_CheckGraphicsMemory();
1624 { /* Set a default viewport */
1628 vp.Width = *(pPresentationParameters->BackBufferWidth);
1629 vp.Height = *(pPresentationParameters->BackBufferHeight);
1632 IWineD3DDevice_SetViewport((IWineD3DDevice *)object, &vp);
1636 /* Initialize the current view state */
1637 object->modelview_valid = 1;
1638 object->proj_valid = 0;
1639 object->view_ident = 1;
1640 object->last_was_rhw = 0;
1641 glGetIntegerv(GL_MAX_LIGHTS, &object->maxConcurrentLights);
1642 TRACE("(%p,%d) All defaults now set up, leaving CreateDevice with %p\n", This, Adapter, object);
1644 /* Clear the screen */
1645 IWineD3DDevice_Clear((IWineD3DDevice *) object, 0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET, 0x00, 1.0, 0);
1647 } else { /* End of FIXME: remove when dx8 merged in */
1649 FIXME("(%p) Incomplete stub for d3d8\n", This);
1654 create_device_error:
1655 if (object->updateStateBlock != NULL) {
1656 IWineD3DStateBlock_Release((IWineD3DStateBlock *)object->updateStateBlock);
1657 object->updateStateBlock = NULL;
1659 if (object->stateBlock != NULL) {
1660 IWineD3DStateBlock_Release((IWineD3DStateBlock *)object->stateBlock);
1661 object->stateBlock = NULL;
1663 if (object->renderTarget != NULL) {
1664 IWineD3DSurface_Release(object->renderTarget);
1665 object->renderTarget = NULL;
1667 if (object->stencilBufferTarget != NULL) {
1668 IWineD3DSurface_Release(object->stencilBufferTarget);
1669 object->stencilBufferTarget = NULL;
1671 if (object->stencilBufferTarget != NULL) {
1672 IWineD3DSurface_Release(object->stencilBufferTarget);
1673 object->stencilBufferTarget = NULL;
1675 if (swapchain != NULL) {
1676 IWineD3DSwapChain_Release((IWineD3DSwapChain *)swapchain);
1679 HeapFree(GetProcessHeap(), 0, object);
1680 *ppReturnedDeviceInterface = NULL;
1681 return D3DERR_INVALIDCALL;
1685 HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
1686 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1687 IUnknown_AddRef(This->parent);
1688 *pParent = This->parent;
1692 /**********************************************************
1693 * IWineD3D VTbl follows
1694 **********************************************************/
1696 const IWineD3DVtbl IWineD3D_Vtbl =
1699 IWineD3DImpl_QueryInterface,
1700 IWineD3DImpl_AddRef,
1701 IWineD3DImpl_Release,
1703 IWineD3DImpl_GetParent,
1704 IWineD3DImpl_GetAdapterCount,
1705 IWineD3DImpl_RegisterSoftwareDevice,
1706 IWineD3DImpl_GetAdapterMonitor,
1707 IWineD3DImpl_GetAdapterModeCount,
1708 IWineD3DImpl_EnumAdapterModes,
1709 IWineD3DImpl_GetAdapterDisplayMode,
1710 IWineD3DImpl_GetAdapterIdentifier,
1711 IWineD3DImpl_CheckDeviceMultiSampleType,
1712 IWineD3DImpl_CheckDepthStencilMatch,
1713 IWineD3DImpl_CheckDeviceType,
1714 IWineD3DImpl_CheckDeviceFormat,
1715 IWineD3DImpl_CheckDeviceFormatConversion,
1716 IWineD3DImpl_GetDeviceCaps,
1717 IWineD3DImpl_CreateDevice