2 * IDirect3D8 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
36 #include "d3d8_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
39 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
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 */
51 static const D3DFORMAT device_formats[NUM_FORMATS] = {
61 static void IDirect3D8Impl_FillGLCaps(LPDIRECT3D8 iface, Display* display);
64 /* retrieve the X display to use on a given DC */
65 inline static Display *get_display( HDC hdc )
68 enum x11drv_escape_codes escape = X11DRV_GET_DISPLAY;
70 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
71 sizeof(display), (LPSTR)&display )) display = NULL;
75 /* IDirect3D IUnknown parts follow: */
76 HRESULT WINAPI IDirect3D8Impl_QueryInterface(LPDIRECT3D8 iface,REFIID riid,LPVOID *ppobj)
78 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
80 if (IsEqualGUID(riid, &IID_IUnknown)
81 || IsEqualGUID(riid, &IID_IDirect3D8)) {
82 IDirect3D8Impl_AddRef(iface);
87 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
91 ULONG WINAPI IDirect3D8Impl_AddRef(LPDIRECT3D8 iface) {
92 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
93 ULONG ref = InterlockedIncrement(&This->ref);
95 TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
100 ULONG WINAPI IDirect3D8Impl_Release(LPDIRECT3D8 iface) {
101 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
102 ULONG ref = InterlockedDecrement(&This->ref);
104 TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
107 IWineD3D_Release(This->WineD3D);
108 HeapFree(GetProcessHeap(), 0, This);
113 /* IDirect3D Interface follow: */
114 HRESULT WINAPI IDirect3D8Impl_RegisterSoftwareDevice (LPDIRECT3D8 iface, void* pInitializeFunction) {
115 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
116 return IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
119 UINT WINAPI IDirect3D8Impl_GetAdapterCount (LPDIRECT3D8 iface) {
120 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
121 return IWineD3D_GetAdapterCount(This->WineD3D);
124 HRESULT WINAPI IDirect3D8Impl_GetAdapterIdentifier (LPDIRECT3D8 iface,
125 UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8* pIdentifier) {
126 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
127 WINED3DADAPTER_IDENTIFIER adapter_id;
129 /* dx8 and dx9 have different structures to be filled in, with incompatible
130 layouts so pass in pointers to the places to be filled via an internal
132 adapter_id.Driver = pIdentifier->Driver;
133 adapter_id.Description = pIdentifier->Description;
134 adapter_id.DeviceName = NULL;
135 adapter_id.DriverVersion = &pIdentifier->DriverVersion;
136 adapter_id.VendorId = &pIdentifier->VendorId;
137 adapter_id.DeviceId = &pIdentifier->DeviceId;
138 adapter_id.SubSysId = &pIdentifier->SubSysId;
139 adapter_id.Revision = &pIdentifier->Revision;
140 adapter_id.DeviceIdentifier = &pIdentifier->DeviceIdentifier;
141 adapter_id.WHQLLevel = &pIdentifier->WHQLLevel;
143 return IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
146 UINT WINAPI IDirect3D8Impl_GetAdapterModeCount (LPDIRECT3D8 iface,UINT Adapter) {
147 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
148 return IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, D3DFMT_UNKNOWN);
151 HRESULT WINAPI IDirect3D8Impl_EnumAdapterModes (LPDIRECT3D8 iface, UINT Adapter, UINT Mode, D3DDISPLAYMODE* pMode) {
152 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
153 return IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, D3DFMT_UNKNOWN, Mode, pMode);
156 HRESULT WINAPI IDirect3D8Impl_GetAdapterDisplayMode (LPDIRECT3D8 iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
157 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
158 return IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, pMode);
161 HRESULT WINAPI IDirect3D8Impl_CheckDeviceType (LPDIRECT3D8 iface,
162 UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
163 D3DFORMAT BackBufferFormat, BOOL Windowed) {
164 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
165 return IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, DisplayFormat,
166 BackBufferFormat, Windowed);
169 HRESULT WINAPI IDirect3D8Impl_CheckDeviceFormat (LPDIRECT3D8 iface,
170 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
171 DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
172 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
173 return IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, AdapterFormat,
174 Usage, RType, CheckFormat);
177 HRESULT WINAPI IDirect3D8Impl_CheckDeviceMultiSampleType(LPDIRECT3D8 iface,
178 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
179 BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType) {
180 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
181 return IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType, SurfaceFormat,
182 Windowed, MultiSampleType, NULL);
185 HRESULT WINAPI IDirect3D8Impl_CheckDepthStencilMatch(LPDIRECT3D8 iface,
186 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
187 D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
188 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
189 return IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType, AdapterFormat,
190 RenderTargetFormat, DepthStencilFormat);
193 HRESULT WINAPI IDirect3D8Impl_GetDeviceCaps(LPDIRECT3D8 iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8* pCaps) {
194 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
195 HRESULT hrc = D3D_OK;
196 WINED3DCAPS *pWineCaps;
198 TRACE("(%p) Relay %d %u %p\n", This, Adapter, DeviceType, pCaps);
201 return D3DERR_INVALIDCALL;
203 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
204 if(pWineCaps == NULL){
205 return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
207 D3D8CAPSTOWINECAPS(pCaps, pWineCaps)
208 hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
209 HeapFree(GetProcessHeap(), 0, pWineCaps);
210 TRACE("(%p) returning %p\n", This, pCaps);
214 HMONITOR WINAPI IDirect3D8Impl_GetAdapterMonitor(LPDIRECT3D8 iface, UINT Adapter) {
215 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
216 return IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
219 static void IDirect3D8Impl_FillGLCaps(LPDIRECT3D8 iface, Display* display) {
220 const char *GL_Extensions = NULL;
221 const char *GLX_Extensions = NULL;
223 const char* gl_string = NULL;
224 const char* gl_string_cursor = NULL;
227 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
229 if (This->gl_info.bIsFilled) return;
230 This->gl_info.bIsFilled = 1;
232 TRACE_(d3d_caps)("(%p, %p)\n", This, display);
234 if (NULL != display) {
235 test = glXQueryVersion(display, &major, &minor);
236 This->gl_info.glx_version = ((major & 0x0000FFFF) << 16) | (minor & 0x0000FFFF);
237 gl_string = glXGetClientString(display, GLX_VENDOR);
239 gl_string = (const char*) glGetString(GL_VENDOR);
242 if (strstr(gl_string, "NVIDIA")) {
243 This->gl_info.gl_vendor = VENDOR_NVIDIA;
244 } else if (strstr(gl_string, "ATI")) {
245 This->gl_info.gl_vendor = VENDOR_ATI;
247 This->gl_info.gl_vendor = VENDOR_WINE;
250 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), This->gl_info.gl_vendor);
252 gl_string = (const char*) glGetString(GL_VERSION);
253 switch (This->gl_info.gl_vendor) {
255 gl_string_cursor = strstr(gl_string, "NVIDIA");
256 gl_string_cursor = strstr(gl_string_cursor, " ");
257 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
258 if (*gl_string_cursor) {
262 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
263 tmp[cursor++] = *gl_string_cursor;
269 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
272 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
273 tmp[cursor++] = *gl_string_cursor;
282 gl_string_cursor = strchr(gl_string, '-');
283 if (gl_string_cursor) {
287 /* Check if version number is of the form x.y.z */
288 if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
290 if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
292 if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
294 if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
296 /* Mark version number as malformed */
298 gl_string_cursor = 0;
300 if (!gl_string_cursor)
301 WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
303 major = *gl_string_cursor - '0';
304 minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
311 This->gl_info.gl_driver_version = MAKEDWORD_VERSION(major, minor);
313 FIXME_(d3d_caps)("found GL_VERSION (%s)->(0x%08lx)\n", debugstr_a(gl_string), This->gl_info.gl_driver_version);
315 gl_string = (const char*) glGetString(GL_RENDERER);
316 strcpy(This->gl_info.gl_renderer, gl_string);
318 switch (This->gl_info.gl_vendor) {
320 if (strstr(This->gl_info.gl_renderer, "GeForce4 Ti")) {
321 This->gl_info.gl_card = CARD_NVIDIA_GEFORCE4_TI4600;
322 } else if (strstr(This->gl_info.gl_renderer, "GeForceFX")) {
323 This->gl_info.gl_card = CARD_NVIDIA_GEFORCEFX_5900ULTRA;
325 This->gl_info.gl_card = CARD_NVIDIA_GEFORCE4_TI4600;
329 if (strstr(This->gl_info.gl_renderer, "RADEON 9800 PRO")) {
330 This->gl_info.gl_card = CARD_ATI_RADEON_9800PRO;
331 } else if (strstr(This->gl_info.gl_renderer, "RADEON 9700 PRO")) {
332 This->gl_info.gl_card = CARD_ATI_RADEON_9700PRO;
334 This->gl_info.gl_card = CARD_ATI_RADEON_8500;
338 This->gl_info.gl_card = CARD_WINE;
342 FIXME_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(This->gl_info.gl_renderer), This->gl_info.gl_card);
345 * Initialize openGL extension related variables
346 * with Default values
348 memset(&This->gl_info.supported, 0, sizeof(This->gl_info.supported));
349 This->gl_info.max_textures = 1;
350 This->gl_info.ps_arb_version = PS_VERSION_NOT_SUPPORTED;
351 This->gl_info.vs_arb_version = VS_VERSION_NOT_SUPPORTED;
352 This->gl_info.vs_nv_version = VS_VERSION_NOT_SUPPORTED;
353 This->gl_info.vs_ati_version = VS_VERSION_NOT_SUPPORTED;
355 #define USE_GL_FUNC(type, pfn) This->gl_info.pfn = NULL;
359 /* Retrieve opengl defaults */
360 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
361 This->gl_info.max_clipplanes = min(MAX_CLIPPLANES, gl_max);
362 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
364 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
365 This->gl_info.max_lights = gl_max;
366 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
368 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
369 GL_Extensions = (const char*) glGetString(GL_EXTENSIONS);
370 TRACE_(d3d_caps)("GL_Extensions reported:\n");
372 if (NULL == GL_Extensions) {
373 ERR(" GL_Extensions returns NULL\n");
375 while (*GL_Extensions != 0x00) {
376 const char *Start = GL_Extensions;
379 memset(ThisExtn, 0x00, sizeof(ThisExtn));
380 while (*GL_Extensions != ' ' && *GL_Extensions != 0x00) {
383 memcpy(ThisExtn, Start, (GL_Extensions - Start));
384 TRACE_(d3d_caps)("- %s\n", ThisExtn);
389 if (strcmp(ThisExtn, "GL_ARB_fragment_program") == 0) {
390 This->gl_info.ps_arb_version = PS_VERSION_11;
391 TRACE_(d3d_caps)(" FOUND: ARB Pixel Shader support - version=%02x\n", This->gl_info.ps_arb_version);
392 This->gl_info.supported[ARB_FRAGMENT_PROGRAM] = TRUE;
393 } else if (strcmp(ThisExtn, "GL_ARB_multisample") == 0) {
394 TRACE_(d3d_caps)(" FOUND: ARB Multisample support\n");
395 This->gl_info.supported[ARB_MULTISAMPLE] = TRUE;
396 } else if (strcmp(ThisExtn, "GL_ARB_multitexture") == 0) {
397 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
398 TRACE_(d3d_caps)(" FOUND: ARB Multitexture support - GL_MAX_TEXTURE_UNITS_ARB=%u\n", gl_max);
399 This->gl_info.supported[ARB_MULTITEXTURE] = TRUE;
400 This->gl_info.max_textures = min(8, gl_max);
401 } else if (strcmp(ThisExtn, "GL_ARB_point_sprite") == 0) {
402 TRACE_(d3d_caps)(" FOUND: ARB Point sprite support\n");
403 This->gl_info.supported[ARB_POINT_SPRITE] = TRUE;
404 } else if (strcmp(ThisExtn, "GL_ARB_texture_cube_map") == 0) {
405 TRACE_(d3d_caps)(" FOUND: ARB Texture Cube Map support\n");
406 This->gl_info.supported[ARB_TEXTURE_CUBE_MAP] = TRUE;
407 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
408 This->gl_info.supported[NV_TEXGEN_REFLECTION] = TRUE;
409 } else if (strcmp(ThisExtn, "GL_ARB_texture_compression") == 0) {
410 TRACE_(d3d_caps)(" FOUND: ARB Texture Compression support\n");
411 This->gl_info.supported[ARB_TEXTURE_COMPRESSION] = TRUE;
412 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_add") == 0) {
413 TRACE_(d3d_caps)(" FOUND: ARB Texture Env Add support\n");
414 This->gl_info.supported[ARB_TEXTURE_ENV_ADD] = TRUE;
415 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_combine") == 0) {
416 TRACE_(d3d_caps)(" FOUND: ARB Texture Env combine support\n");
417 This->gl_info.supported[ARB_TEXTURE_ENV_COMBINE] = TRUE;
418 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_dot3") == 0) {
419 TRACE_(d3d_caps)(" FOUND: ARB Dot3 support\n");
420 This->gl_info.supported[ARB_TEXTURE_ENV_DOT3] = TRUE;
421 } else if (strcmp(ThisExtn, "GL_ARB_texture_border_clamp") == 0) {
422 TRACE_(d3d_caps)(" FOUND: ARB Texture border clamp support\n");
423 This->gl_info.supported[ARB_TEXTURE_BORDER_CLAMP] = TRUE;
424 } else if (strcmp(ThisExtn, "GL_ARB_texture_mirrored_repeat") == 0) {
425 TRACE_(d3d_caps)(" FOUND: ARB Texture mirrored repeat support\n");
426 This->gl_info.supported[ARB_TEXTURE_MIRRORED_REPEAT] = TRUE;
427 } else if (strstr(ThisExtn, "GL_ARB_vertex_program")) {
428 This->gl_info.vs_arb_version = VS_VERSION_11;
429 TRACE_(d3d_caps)(" FOUND: ARB Vertex Shader support - version=%02x\n", This->gl_info.vs_arb_version);
430 This->gl_info.supported[ARB_VERTEX_PROGRAM] = TRUE;
435 } else if (strcmp(ThisExtn, "GL_EXT_fog_coord") == 0) {
436 TRACE_(d3d_caps)(" FOUND: EXT Fog coord support\n");
437 This->gl_info.supported[EXT_FOG_COORD] = TRUE;
438 } else if (strcmp(ThisExtn, "GL_EXT_paletted_texture") == 0) { /* handle paletted texture extensions */
439 TRACE_(d3d_caps)(" FOUND: EXT Paletted texture support\n");
440 This->gl_info.supported[EXT_PALETTED_TEXTURE] = TRUE;
441 } else if (strcmp(ThisExtn, "GL_EXT_point_parameters") == 0) {
442 TRACE_(d3d_caps)(" FOUND: EXT Point parameters support\n");
443 This->gl_info.supported[EXT_POINT_PARAMETERS] = TRUE;
444 } else if (strcmp(ThisExtn, "GL_EXT_secondary_color") == 0) {
445 TRACE_(d3d_caps)(" FOUND: EXT Secondary coord support\n");
446 This->gl_info.supported[EXT_SECONDARY_COLOR] = TRUE;
447 } else if (strcmp(ThisExtn, "GL_EXT_stencil_wrap") == 0) {
448 TRACE_(d3d_caps)(" FOUND: EXT Stencil wrap support\n");
449 This->gl_info.supported[EXT_STENCIL_WRAP] = TRUE;
450 } else if (strcmp(ThisExtn, "GL_EXT_texture_compression_s3tc") == 0) {
451 TRACE_(d3d_caps)(" FOUND: EXT Texture S3TC compression support\n");
452 This->gl_info.supported[EXT_TEXTURE_COMPRESSION_S3TC] = TRUE;
453 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_add") == 0) {
454 TRACE_(d3d_caps)(" FOUND: EXT Texture Env Add support\n");
455 This->gl_info.supported[EXT_TEXTURE_ENV_ADD] = TRUE;
456 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_combine") == 0) {
457 TRACE_(d3d_caps)(" FOUND: EXT Texture Env combine support\n");
458 This->gl_info.supported[EXT_TEXTURE_ENV_COMBINE] = TRUE;
459 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_dot3") == 0) {
460 TRACE_(d3d_caps)(" FOUND: EXT Dot3 support\n");
461 This->gl_info.supported[EXT_TEXTURE_ENV_DOT3] = TRUE;
462 } else if (strcmp(ThisExtn, "GL_EXT_texture_filter_anisotropic") == 0) {
463 TRACE_(d3d_caps)(" FOUND: EXT Texture Anisotropic filter support\n");
464 This->gl_info.supported[EXT_TEXTURE_FILTER_ANISOTROPIC] = TRUE;
465 } else if (strcmp(ThisExtn, "GL_EXT_texture_lod") == 0) {
466 TRACE_(d3d_caps)(" FOUND: EXT Texture LOD support\n");
467 This->gl_info.supported[EXT_TEXTURE_LOD] = TRUE;
468 } else if (strcmp(ThisExtn, "GL_EXT_texture_lod_bias") == 0) {
469 TRACE_(d3d_caps)(" FOUND: EXT Texture LOD bias support\n");
470 This->gl_info.supported[EXT_TEXTURE_LOD_BIAS] = TRUE;
471 } else if (strcmp(ThisExtn, "GL_EXT_vertex_weighting") == 0) {
472 TRACE_(d3d_caps)(" FOUND: EXT Vertex weighting support\n");
473 This->gl_info.supported[EXT_VERTEX_WEIGHTING] = TRUE;
478 } else if (strstr(ThisExtn, "GL_NV_fog_distance")) {
479 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Fog Distance support\n");
480 This->gl_info.supported[NV_FOG_DISTANCE] = TRUE;
481 } else if (strstr(ThisExtn, "GL_NV_fragment_program")) {
482 This->gl_info.ps_nv_version = PS_VERSION_11;
483 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Pixel Shader support - version=%02x\n", This->gl_info.ps_nv_version);
484 } else if (strcmp(ThisExtn, "GL_NV_register_combiners") == 0) {
485 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Register combiners (1) support\n");
486 This->gl_info.supported[NV_REGISTER_COMBINERS] = TRUE;
487 } else if (strcmp(ThisExtn, "GL_NV_register_combiners2") == 0) {
488 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Register combiners (2) support\n");
489 This->gl_info.supported[NV_REGISTER_COMBINERS2] = TRUE;
490 } else if (strcmp(ThisExtn, "GL_NV_texgen_reflection") == 0) {
491 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Gen Reflection support\n");
492 This->gl_info.supported[NV_TEXGEN_REFLECTION] = TRUE;
493 } else if (strcmp(ThisExtn, "GL_NV_texture_env_combine4") == 0) {
494 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Env combine (4) support\n");
495 This->gl_info.supported[NV_TEXTURE_ENV_COMBINE4] = TRUE;
496 } else if (strcmp(ThisExtn, "GL_NV_texture_shader") == 0) {
497 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (1) support\n");
498 This->gl_info.supported[NV_TEXTURE_SHADER] = TRUE;
499 } else if (strcmp(ThisExtn, "GL_NV_texture_shader2") == 0) {
500 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (2) support\n");
501 This->gl_info.supported[NV_TEXTURE_SHADER2] = TRUE;
502 } else if (strcmp(ThisExtn, "GL_NV_texture_shader3") == 0) {
503 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (3) support\n");
504 This->gl_info.supported[NV_TEXTURE_SHADER3] = TRUE;
505 } else if (strstr(ThisExtn, "GL_NV_vertex_program")) {
506 This->gl_info.vs_nv_version = max(This->gl_info.vs_nv_version, (0 == strcmp(ThisExtn, "GL_NV_vertex_program1_1")) ? VS_VERSION_11 : VS_VERSION_10);
507 This->gl_info.vs_nv_version = max(This->gl_info.vs_nv_version, (0 == strcmp(ThisExtn, "GL_NV_vertex_program2")) ? VS_VERSION_20 : VS_VERSION_10);
508 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Vertex Shader support - version=%02x\n", This->gl_info.vs_nv_version);
509 This->gl_info.supported[NV_VERTEX_PROGRAM] = TRUE;
515 } else if (strcmp(ThisExtn, "GL_ATI_texture_env_combine3") == 0) {
516 TRACE_(d3d_caps)(" FOUND: ATI Texture Env combine (3) support\n");
517 This->gl_info.supported[ATI_TEXTURE_ENV_COMBINE3] = TRUE;
518 } else if (strcmp(ThisExtn, "GL_ATI_texture_mirror_once") == 0) {
519 TRACE_(d3d_caps)(" FOUND: ATI Texture Mirror Once support\n");
520 This->gl_info.supported[ATI_TEXTURE_MIRROR_ONCE] = TRUE;
521 } else if (strcmp(ThisExtn, "GL_EXT_vertex_shader") == 0) {
522 This->gl_info.vs_ati_version = VS_VERSION_11;
523 TRACE_(d3d_caps)(" FOUND: ATI (EXT) Vertex Shader support - version=%02x\n", This->gl_info.vs_ati_version);
524 This->gl_info.supported[EXT_VERTEX_SHADER] = TRUE;
528 if (*GL_Extensions == ' ') GL_Extensions++;
532 #define USE_GL_FUNC(type, pfn) This->gl_info.pfn = (type) glXGetProcAddressARB( (const GLubyte *) #pfn);
536 if (display != NULL) {
537 GLX_Extensions = glXQueryExtensionsString(display, DefaultScreen(display));
538 TRACE_(d3d_caps)("GLX_Extensions reported:\n");
540 if (NULL == GLX_Extensions) {
541 ERR(" GLX_Extensions returns NULL\n");
543 while (*GLX_Extensions != 0x00) {
544 const char *Start = GLX_Extensions;
547 memset(ThisExtn, 0x00, sizeof(ThisExtn));
548 while (*GLX_Extensions != ' ' && *GLX_Extensions != 0x00) {
551 memcpy(ThisExtn, Start, (GLX_Extensions - Start));
552 TRACE_(d3d_caps)("- %s\n", ThisExtn);
553 if (*GLX_Extensions == ' ') GLX_Extensions++;
558 #define USE_GL_FUNC(type, pfn) This->gl_info.pfn = (type) glXGetProcAddressARB( (const GLubyte *) #pfn);
562 /* Only save the values obtained when a display is provided */
563 if (display != NULL) This->isGLInfoValid = TRUE;
567 /* Internal function called back during the CreateDevice to create a render target */
568 HRESULT WINAPI D3D8CB_CreateRenderTarget(IUnknown *device, UINT Width, UINT Height,
569 WINED3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
570 DWORD MultisampleQuality, BOOL Lockable,
571 IWineD3DSurface** ppSurface, HANDLE* pSharedHandle) {
572 HRESULT res = D3D_OK;
573 IDirect3DSurface8Impl *d3dSurface = NULL;
575 /* Note - Throw away MultisampleQuality and SharedHandle - only relevant for d3d9 */
576 res = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)device, Width, Height,
577 (D3DFORMAT)Format, MultiSample, Lockable,
578 (IDirect3DSurface8 **)&d3dSurface);
580 *ppSurface = d3dSurface->wineD3DSurface;
585 /* Callback for creating the inplicite swapchain when the device is created */
586 HRESULT WINAPI D3D8CB_CreateAdditionalSwapChain(IUnknown *device,
587 WINED3DPRESENT_PARAMETERS* pPresentationParameters,
588 IWineD3DSwapChain ** ppSwapChain){
589 HRESULT res = D3D_OK;
590 IDirect3DSwapChain8Impl *d3dSwapChain = NULL;
591 /* We have to pass the presentation parameters back and forth */
592 D3DPRESENT_PARAMETERS localParameters;
593 localParameters.BackBufferWidth = *(pPresentationParameters->BackBufferWidth);
594 localParameters.BackBufferHeight = *(pPresentationParameters->BackBufferHeight);
595 localParameters.BackBufferFormat = *(pPresentationParameters->BackBufferFormat);
596 localParameters.BackBufferCount = *(pPresentationParameters->BackBufferCount);
597 localParameters.MultiSampleType = *(pPresentationParameters->MultiSampleType);
599 /* localParameters.MultiSampleQuality = *(pPresentationParameters->MultiSampleQuality); */
600 localParameters.SwapEffect = *(pPresentationParameters->SwapEffect);
601 localParameters.hDeviceWindow = *(pPresentationParameters->hDeviceWindow);
602 localParameters.Windowed = *(pPresentationParameters->Windowed);
603 localParameters.EnableAutoDepthStencil = *(pPresentationParameters->EnableAutoDepthStencil);
604 localParameters.AutoDepthStencilFormat = *(pPresentationParameters->AutoDepthStencilFormat);
605 localParameters.Flags = *(pPresentationParameters->Flags);
606 localParameters.FullScreen_RefreshRateInHz = *(pPresentationParameters->FullScreen_RefreshRateInHz);
608 /* localParameters.PresentationInterval = *(pPresentationParameters->PresentationInterval); */
610 TRACE("(%p) rellaying\n", device);
611 /*copy the presentation parameters*/
612 res = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)device, &localParameters, (IDirect3DSwapChain8 **)&d3dSwapChain);
615 *ppSwapChain = d3dSwapChain->wineD3DSwapChain;
617 FIXME("failed to create additional swap chain\n");
620 /* Copy back the presentation parameters */
621 TRACE("(%p) setting up return parameters\n", device);
622 *pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
623 *pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
624 *pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
625 *pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
626 *pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
627 /* *pPresentationParameters->MultiSampleQuality leave alone in case wined3d set something internally */
628 *pPresentationParameters->SwapEffect = localParameters.SwapEffect;
629 *pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
630 *pPresentationParameters->Windowed = localParameters.Windowed;
631 *pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
632 *pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
633 *pPresentationParameters->Flags = localParameters.Flags;
634 *pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
635 /* *pPresentationParameters->PresentationInterval leave alone in case wined3d set something internally */
640 HRESULT WINAPI IDirect3D8Impl_CreateDevice (LPDIRECT3D8 iface,
641 UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
642 DWORD BehaviourFlags, D3DPRESENT_PARAMETERS* pPresentationParameters,
643 IDirect3DDevice8** ppReturnedDeviceInterface) {
644 IDirect3DDevice8Impl *object;
647 XVisualInfo template;
649 WINED3DPRESENT_PARAMETERS localParameters;
651 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
652 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %lx, PresParms: %p, RetDevInt: %p)\n", This, Adapter, DeviceType,
653 hFocusWindow, BehaviourFlags, pPresentationParameters, ppReturnedDeviceInterface);
655 if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
656 return D3DERR_INVALIDCALL;
659 /* Allocate the storage for the device */
660 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice8Impl));
661 if (NULL == object) {
662 return D3DERR_OUTOFVIDEOMEMORY;
664 object->lpVtbl = &Direct3DDevice8_Vtbl;
666 object->direct3d8 = This;
667 /** The device AddRef the direct3d8 Interface else crash in propers clients codes */
668 IDirect3D8_AddRef((LPDIRECT3D8) object->direct3d8);
670 /* Allocate an associated WineD3DDevice object */
671 localParameters.BackBufferWidth = &pPresentationParameters->BackBufferWidth;
672 localParameters.BackBufferHeight = &pPresentationParameters->BackBufferHeight;
673 localParameters.BackBufferFormat = (WINED3DFORMAT *)&pPresentationParameters->BackBufferFormat;
674 localParameters.BackBufferCount = &pPresentationParameters->BackBufferCount;
675 localParameters.MultiSampleType = &pPresentationParameters->MultiSampleType;
676 localParameters.MultiSampleQuality = NULL; /* New at dx9 */
677 localParameters.SwapEffect = &pPresentationParameters->SwapEffect;
678 localParameters.hDeviceWindow = &pPresentationParameters->hDeviceWindow;
679 localParameters.Windowed = &pPresentationParameters->Windowed;
680 localParameters.EnableAutoDepthStencil = &pPresentationParameters->EnableAutoDepthStencil;
681 localParameters.AutoDepthStencilFormat = (WINED3DFORMAT *)&pPresentationParameters->AutoDepthStencilFormat;
682 localParameters.Flags = &pPresentationParameters->Flags;
683 localParameters.FullScreen_RefreshRateInHz = &pPresentationParameters->FullScreen_RefreshRateInHz;
684 localParameters.PresentationInterval = &pPresentationParameters->FullScreen_PresentationInterval; /* Renamed in dx9 */
685 IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags, &localParameters, &object->WineD3DDevice, (IUnknown *)object, D3D8CB_CreateAdditionalSwapChain);
687 /** use StateBlock Factory here, for creating the startup stateBlock */
688 object->StateBlock = NULL;
689 IDirect3DDeviceImpl_CreateStateBlock(object, D3DSBT_ALL, NULL);
690 object->UpdateStateBlock = object->StateBlock;
692 /* Save the creation parameters */
693 object->CreateParms.AdapterOrdinal = Adapter;
694 object->CreateParms.DeviceType = DeviceType;
695 object->CreateParms.hFocusWindow = hFocusWindow;
696 object->CreateParms.BehaviorFlags = BehaviourFlags;
698 *ppReturnedDeviceInterface = (LPDIRECT3DDEVICE8) object;
700 /* Initialize settings */
701 object->PresentParms.BackBufferCount = 1; /* Opengl only supports one? */
702 object->adapterNo = Adapter;
703 object->devType = DeviceType;
705 /* Initialize openGl - Note the visual is chosen as the window is created and the glcontext cannot
706 use different properties after that point in time. FIXME: How to handle when requested format
707 doesn't match actual visual? Cannot choose one here - code removed as it ONLY works if the one
708 it chooses is identical to the one already being used! */
709 /* FIXME: Handle stencil appropriately via EnableAutoDepthStencil / AutoDepthStencilFormat */
711 /* Which hwnd are we using? */
712 whichHWND = pPresentationParameters->hDeviceWindow;
714 whichHWND = hFocusWindow;
716 whichHWND = GetAncestor(whichHWND, GA_ROOT);
717 if ( !( object->win = (Window)GetPropA(whichHWND, "__wine_x11_whole_window") ) ) {
718 ERR("Can't get drawable (window), HWND:%p doesn't have the property __wine_x11_whole_window\n", whichHWND);
719 return D3DERR_NOTAVAILABLE;
721 object->win_handle = whichHWND;
723 hDc = GetDC(whichHWND);
724 object->display = get_display(hDc);
726 TRACE("(%p)->(DepthStencil:(%u,%s), BackBufferFormat:(%u,%s))\n", This,
727 pPresentationParameters->AutoDepthStencilFormat, debug_d3dformat(pPresentationParameters->AutoDepthStencilFormat),
728 pPresentationParameters->BackBufferFormat, debug_d3dformat(pPresentationParameters->BackBufferFormat));
732 /* Create a context based off the properties of the existing visual */
733 template.visualid = (VisualID)GetPropA(GetDesktopWindow(), "__wine_x11_visual_id");
734 object->visInfo = XGetVisualInfo(object->display, VisualIDMask, &template, &num);
735 if (NULL == object->visInfo) {
736 ERR("cannot really get XVisual\n");
738 return D3DERR_NOTAVAILABLE;
740 object->glCtx = glXCreateContext(object->display, object->visInfo, NULL, GL_TRUE);
741 if (NULL == object->glCtx) {
742 ERR("cannot create glxContext\n");
744 return D3DERR_NOTAVAILABLE;
748 ReleaseDC(whichHWND, hDc);
750 if (object->glCtx == NULL) {
751 ERR("Error in context creation !\n");
752 return D3DERR_INVALIDCALL;
754 TRACE("Context created (HWND=%p, glContext=%p, Window=%ld, VisInfo=%p)\n",
755 whichHWND, object->glCtx, object->win, object->visInfo);
758 /* If not windowed, need to go fullscreen, and resize the HWND to the appropriate */
760 if (!pPresentationParameters->Windowed) {
765 memset(&devmode, 0, sizeof(DEVMODEW));
766 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
767 MultiByteToWideChar(CP_ACP, 0, "Gamers CG", -1, devmode.dmDeviceName, CCHDEVICENAME);
768 hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
769 bpp = GetDeviceCaps(hdc, BITSPIXEL);
771 devmode.dmBitsPerPel = (bpp >= 24) ? 32 : bpp;/*Stupid XVidMode cannot change bpp D3DFmtGetBpp(object, pPresentationParameters->BackBufferFormat);*/
772 devmode.dmPelsWidth = pPresentationParameters->BackBufferWidth;
773 devmode.dmPelsHeight = pPresentationParameters->BackBufferHeight;
774 ChangeDisplaySettingsExW(devmode.dmDeviceName, &devmode, object->win_handle, CDS_FULLSCREEN, NULL);
776 FIXME("Requested full screen support not implemented, expect windowed operation\n");
779 /* Make popup window */
780 SetWindowLongA(whichHWND, GWL_STYLE, WS_POPUP);
781 SetWindowPos(object->win_handle, HWND_TOP, 0, 0,
782 pPresentationParameters->BackBufferWidth,
783 pPresentationParameters->BackBufferHeight, SWP_SHOWWINDOW | SWP_FRAMECHANGED);
786 TRACE("Creating back buffer\n");
787 /* MSDN: If Windowed is TRUE and either of the BackBufferWidth/Height values is zero,
788 then the corresponding dimension of the client area of the hDeviceWindow
789 (or the focus window, if hDeviceWindow is NULL) is taken. */
790 if (pPresentationParameters->Windowed && ((pPresentationParameters->BackBufferWidth == 0) ||
791 (pPresentationParameters->BackBufferHeight == 0))) {
794 GetClientRect(whichHWND, &Rect);
796 if (pPresentationParameters->BackBufferWidth == 0) {
797 pPresentationParameters->BackBufferWidth = Rect.right;
798 TRACE("Updating width to %d\n", pPresentationParameters->BackBufferWidth);
800 if (pPresentationParameters->BackBufferHeight == 0) {
801 pPresentationParameters->BackBufferHeight = Rect.bottom;
802 TRACE("Updating height to %d\n", pPresentationParameters->BackBufferHeight);
806 /* Save the presentation parms now filled in correctly */
807 memcpy(&object->PresentParms, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
810 IDirect3DDevice8Impl_CreateRenderTarget((LPDIRECT3DDEVICE8) object,
811 pPresentationParameters->BackBufferWidth,
812 pPresentationParameters->BackBufferHeight,
813 pPresentationParameters->BackBufferFormat,
814 pPresentationParameters->MultiSampleType,
816 (LPDIRECT3DSURFACE8*) &object->frontBuffer);
818 IDirect3DDevice8Impl_CreateRenderTarget((LPDIRECT3DDEVICE8) object,
819 pPresentationParameters->BackBufferWidth,
820 pPresentationParameters->BackBufferHeight,
821 pPresentationParameters->BackBufferFormat,
822 pPresentationParameters->MultiSampleType,
824 (LPDIRECT3DSURFACE8*) &object->backBuffer);
826 if (pPresentationParameters->EnableAutoDepthStencil) {
827 IDirect3DDevice8Impl_CreateDepthStencilSurface((LPDIRECT3DDEVICE8) object,
828 pPresentationParameters->BackBufferWidth,
829 pPresentationParameters->BackBufferHeight,
830 pPresentationParameters->AutoDepthStencilFormat,
832 (LPDIRECT3DSURFACE8*) &object->depthStencilBuffer);
834 object->depthStencilBuffer = NULL;
836 TRACE("FrontBuf @ %p, BackBuf @ %p, DepthStencil @ %p\n",object->frontBuffer, object->backBuffer, object->depthStencilBuffer);
838 /* init the default renderTarget management */
839 object->drawable = object->win;
840 object->render_ctx = object->glCtx;
841 object->renderTarget = object->backBuffer;
842 IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) object->renderTarget);
843 object->stencilBufferTarget = object->depthStencilBuffer;
844 if (NULL != object->stencilBufferTarget) {
845 IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) object->stencilBufferTarget);
850 if (glXMakeCurrent(object->display, object->win, object->glCtx) == False) {
851 ERR("Error in setting current context (context %p drawable %ld)!\n", object->glCtx, object->win);
853 checkGLcall("glXMakeCurrent");
855 /* Clear the screen */
856 glClearColor(1.0, 0.0, 0.0, 0.0);
857 checkGLcall("glClearColor");
858 glColor3f(1.0, 1.0, 1.0);
859 checkGLcall("glColor3f");
861 glEnable(GL_LIGHTING);
862 checkGLcall("glEnable");
864 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
865 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);");
867 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
868 checkGLcall("glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
870 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
871 checkGLcall("glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);");
874 * Initialize openGL extension related variables
875 * with Default values
877 IDirect3D8Impl_FillGLCaps(iface, object->display);
879 /* Setup all the devices defaults */
880 IDirect3DDeviceImpl_InitStartupStateBlock(object);
884 { /* Set a default viewport */
888 vp.Width = pPresentationParameters->BackBufferWidth;
889 vp.Height = pPresentationParameters->BackBufferHeight;
892 IDirect3DDevice8Impl_SetViewport((LPDIRECT3DDEVICE8) object, &vp);
895 /* Initialize the current view state */
896 object->modelview_valid = 1;
897 object->proj_valid = 0;
898 object->view_ident = 1;
899 object->last_was_rhw = 0;
900 glGetIntegerv(GL_MAX_LIGHTS, &object->maxConcurrentLights);
901 TRACE("(%p,%d) All defaults now set up, leaving CreateDevice with %p\n", This, Adapter, object);
903 /* Clear the screen */
904 IDirect3DDevice8Impl_Clear((LPDIRECT3DDEVICE8) object, 0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET, 0x00, 1.0, 0);
909 const IDirect3D8Vtbl Direct3D8_Vtbl =
911 IDirect3D8Impl_QueryInterface,
912 IDirect3D8Impl_AddRef,
913 IDirect3D8Impl_Release,
914 IDirect3D8Impl_RegisterSoftwareDevice,
915 IDirect3D8Impl_GetAdapterCount,
916 IDirect3D8Impl_GetAdapterIdentifier,
917 IDirect3D8Impl_GetAdapterModeCount,
918 IDirect3D8Impl_EnumAdapterModes,
919 IDirect3D8Impl_GetAdapterDisplayMode,
920 IDirect3D8Impl_CheckDeviceType,
921 IDirect3D8Impl_CheckDeviceFormat,
922 IDirect3D8Impl_CheckDeviceMultiSampleType,
923 IDirect3D8Impl_CheckDepthStencilMatch,
924 IDirect3D8Impl_GetDeviceCaps,
925 IDirect3D8Impl_GetAdapterMonitor,
926 IDirect3D8Impl_CreateDevice