2 * Direct3D wine internal interface main
4 * Copyright 2002-2003 The wine-d3d team
5 * Copyright 2002-2003 Raphael Junqueira
6 * Copyright 2004 Jason Edmeades
7 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
32 void (*CDECL wine_tsx11_lock_ptr)(void) = NULL;
33 void (*CDECL wine_tsx11_unlock_ptr)(void) = NULL;
36 /* When updating default value here, make sure to update winecfg as well,
37 * where appropriate. */
38 wined3d_settings_t wined3d_settings =
40 VS_HW, /* Hardware by default */
41 PS_HW, /* Hardware by default */
42 VBO_HW, /* Hardware by default */
43 TRUE, /* Use of GLSL enabled by default */
44 ORM_BACKBUFFER, /* Use the backbuffer to do offscreen rendering */
45 RTL_AUTO, /* Automatically determine best locking method */
46 PCI_VENDOR_NONE,/* PCI Vendor ID */
47 PCI_DEVICE_NONE,/* PCI Device ID */
48 0, /* The default of memory is set in FillGLCaps */
49 NULL, /* No wine logo by default */
50 FALSE /* Disable multisampling for now due to Nvidia driver bugs which happens for some users */
53 IWineD3D* WINAPI WineDirect3DCreate(UINT dxVersion, IUnknown *parent) {
56 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
57 object->lpVtbl = &IWineD3D_Vtbl;
58 object->dxVersion = dxVersion;
60 object->parent = parent;
62 if (!InitAdapters(object))
64 WARN("Failed to initialize direct3d adapters, Direct3D will not be available\n");
67 ERR("Direct3D%d is not available without opengl\n", dxVersion);
68 HeapFree(GetProcessHeap(), 0, object);
73 TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
75 return (IWineD3D *)object;
78 static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
80 if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
81 if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
82 return ERROR_FILE_NOT_FOUND;
85 static inline DWORD get_config_key_dword(HKEY defkey, HKEY appkey, const char* name, DWORD *data)
88 DWORD size = sizeof(DWORD);
89 if (0 != appkey && !RegQueryValueExA( appkey, name, 0, &type, (LPBYTE) data, &size ) && (type == REG_DWORD)) return 0;
90 if (0 != defkey && !RegQueryValueExA( defkey, name, 0, &type, (LPBYTE) data, &size ) && (type == REG_DWORD)) return 0;
91 return ERROR_FILE_NOT_FOUND;
94 static void CDECL wined3d_do_nothing(void)
98 static BOOL wined3d_init(HINSTANCE hInstDLL)
101 char buffer[MAX_PATH+10];
102 DWORD size = sizeof(buffer);
108 /* We need our own window class for a fake window which we use to retrieve GL capabilities */
109 /* We might need CS_OWNDC in the future if we notice strange things on Windows.
110 * Various articles/posts about OpenGL problems on Windows recommend this. */
111 wc.style = CS_HREDRAW | CS_VREDRAW;
112 wc.lpfnWndProc = DefWindowProcA;
115 wc.hInstance = hInstDLL;
116 wc.hIcon = LoadIconA(NULL, (LPCSTR)IDI_WINLOGO);
117 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
118 wc.hbrBackground = NULL;
119 wc.lpszMenuName = NULL;
120 wc.lpszClassName = "WineD3D_OpenGL";
122 if (!RegisterClassA(&wc) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
124 ERR("Failed to register window class 'WineD3D_OpenGL'!\n");
128 DisableThreadLibraryCalls(hInstDLL);
130 mod = GetModuleHandleA( "winex11.drv" );
133 wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
134 wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
136 else /* We are most likely on Windows */
138 wine_tsx11_lock_ptr = wined3d_do_nothing;
139 wine_tsx11_unlock_ptr = wined3d_do_nothing;
141 /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
142 if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
144 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
145 if (len && len < MAX_PATH)
148 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
149 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
151 char *p, *appname = buffer;
152 if ((p = strrchr( appname, '/' ))) appname = p + 1;
153 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
154 strcat( appname, "\\Direct3D" );
155 TRACE("appname = [%s]\n", appname);
156 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
157 RegCloseKey( tmpkey );
161 if ( 0 != hkey || 0 != appkey )
163 if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
165 if (!strcmp(buffer,"none"))
167 TRACE("Disable vertex shaders\n");
168 wined3d_settings.vs_mode = VS_NONE;
171 if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
173 if (!strcmp(buffer,"enabled"))
175 TRACE("Allow pixel shaders\n");
176 wined3d_settings.ps_mode = PS_HW;
178 if (!strcmp(buffer,"disabled"))
180 TRACE("Disable pixel shaders\n");
181 wined3d_settings.ps_mode = PS_NONE;
184 if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
186 if (!strcmp(buffer,"none"))
188 TRACE("Disable Vertex Buffer Hardware support\n");
189 wined3d_settings.vbo_mode = VBO_NONE;
191 else if (!strcmp(buffer,"hardware"))
193 TRACE("Allow Vertex Buffer Hardware support\n");
194 wined3d_settings.vbo_mode = VBO_HW;
197 if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
199 if (!strcmp(buffer,"disabled"))
201 TRACE("Use of GL Shading Language disabled\n");
202 wined3d_settings.glslRequested = FALSE;
205 if ( !get_config_key( hkey, appkey, "OffscreenRenderingMode", buffer, size) )
207 if (!strcmp(buffer,"backbuffer"))
209 TRACE("Using the backbuffer for offscreen rendering\n");
210 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
212 else if (!strcmp(buffer,"pbuffer"))
214 TRACE("Using PBuffers for offscreen rendering\n");
215 wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
217 else if (!strcmp(buffer,"fbo"))
219 TRACE("Using FBOs for offscreen rendering\n");
220 wined3d_settings.offscreen_rendering_mode = ORM_FBO;
223 if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
225 if (!strcmp(buffer,"disabled"))
227 TRACE("Disabling render target locking\n");
228 wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
230 else if (!strcmp(buffer,"readdraw"))
232 TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
233 wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
235 else if (!strcmp(buffer,"readtex"))
237 TRACE("Using glReadPixels for render target reading and textures for writing\n");
238 wined3d_settings.rendertargetlock_mode = RTL_READTEX;
240 else if (!strcmp(buffer,"texdraw"))
242 TRACE("Using textures for render target reading and glDrawPixels for writing\n");
243 wined3d_settings.rendertargetlock_mode = RTL_TEXDRAW;
245 else if (!strcmp(buffer,"textex"))
247 TRACE("Reading render targets via textures and writing via textures\n");
248 wined3d_settings.rendertargetlock_mode = RTL_TEXTEX;
251 if ( !get_config_key_dword( hkey, appkey, "VideoPciDeviceID", &tmpvalue) )
253 int pci_device_id = tmpvalue;
255 /* A pci device id is 16-bit */
256 if(pci_device_id > 0xffff)
258 ERR("Invalid value for VideoPciDeviceID. The value should be smaller or equal to 65535 or 0xffff\n");
262 TRACE("Using PCI Device ID %04x\n", pci_device_id);
263 wined3d_settings.pci_device_id = pci_device_id;
266 if ( !get_config_key_dword( hkey, appkey, "VideoPciVendorID", &tmpvalue) )
268 int pci_vendor_id = tmpvalue;
270 /* A pci device id is 16-bit */
271 if(pci_vendor_id > 0xffff)
273 ERR("Invalid value for VideoPciVendorID. The value should be smaller or equal to 65535 or 0xffff\n");
277 TRACE("Using PCI Vendor ID %04x\n", pci_vendor_id);
278 wined3d_settings.pci_vendor_id = pci_vendor_id;
281 if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
283 int TmpVideoMemorySize = atoi(buffer);
284 if(TmpVideoMemorySize > 0)
286 wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
287 TRACE("Use %iMB = %d byte for emulated_textureram\n",
289 wined3d_settings.emulated_textureram);
292 ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
294 if ( !get_config_key( hkey, appkey, "WineLogo", buffer, size) )
296 wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, strlen(buffer) + 1);
297 if(wined3d_settings.logo) strcpy(wined3d_settings.logo, buffer);
299 if ( !get_config_key( hkey, appkey, "Multisampling", buffer, size) )
301 if (!strcmp(buffer,"enabled"))
303 TRACE("Allow multisampling\n");
304 wined3d_settings.allow_multisampling = TRUE;
308 if (wined3d_settings.vs_mode == VS_HW)
309 TRACE("Allow HW vertex shaders\n");
310 if (wined3d_settings.ps_mode == PS_NONE)
311 TRACE("Disable pixel shaders\n");
312 if (wined3d_settings.vbo_mode == VBO_NONE)
313 TRACE("Disable Vertex Buffer Hardware support\n");
314 if (wined3d_settings.glslRequested)
315 TRACE("If supported by your system, GL Shading Language will be used\n");
317 if (appkey) RegCloseKey( appkey );
318 if (hkey) RegCloseKey( hkey );
323 static BOOL wined3d_destroy(void)
325 HeapFree(GetProcessHeap(), 0, wined3d_settings.logo);
330 /* At process attach */
331 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
333 TRACE("WineD3D DLLMain Reason=%u\n", fdwReason);
337 case DLL_PROCESS_ATTACH:
338 return wined3d_init(hInstDLL);
340 case DLL_PROCESS_DETACH:
341 return wined3d_destroy();