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 if (!InitAdapters()) {
57 WARN("Failed to initialize direct3d adapters, Direct3D will not be available\n");
59 ERR("Direct3D%d is not available without opengl\n", dxVersion);
64 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
65 object->lpVtbl = &IWineD3D_Vtbl;
66 object->dxVersion = dxVersion;
68 object->parent = parent;
70 TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
72 return (IWineD3D *)object;
75 static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
77 if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
78 if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
79 return ERROR_FILE_NOT_FOUND;
82 static inline DWORD get_config_key_dword(HKEY defkey, HKEY appkey, const char* name, DWORD *data)
85 DWORD size = sizeof(DWORD);
86 if (0 != appkey && !RegQueryValueExA( appkey, name, 0, &type, (LPBYTE) data, &size ) && (type == REG_DWORD)) return 0;
87 if (0 != defkey && !RegQueryValueExA( defkey, name, 0, &type, (LPBYTE) data, &size ) && (type == REG_DWORD)) return 0;
88 return ERROR_FILE_NOT_FOUND;
91 static void CDECL wined3d_do_nothing(void)
95 /* At process attach */
96 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
98 TRACE("WineD3D DLLMain Reason=%d\n", fdwReason);
99 if (fdwReason == DLL_PROCESS_ATTACH)
102 char buffer[MAX_PATH+10];
103 DWORD size = sizeof(buffer);
109 /* We need our own window class for a fake window which we use to retrieve GL capabilities */
110 /* We might need CS_OWNDC in the future if we notice strange things on Windows.
111 * Various articles/posts about OpenGL problems on Windows recommend this. */
112 wc.style = CS_HREDRAW | CS_VREDRAW;
113 wc.lpfnWndProc = DefWindowProcA;
116 wc.hInstance = hInstDLL;
117 wc.hIcon = LoadIconA(NULL, (LPCSTR)IDI_WINLOGO);
118 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
119 wc.hbrBackground = NULL;
120 wc.lpszMenuName = NULL;
121 wc.lpszClassName = "WineD3D_OpenGL";
123 if (!RegisterClassA(&wc) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
125 ERR("Failed to register window class 'WineD3D_OpenGL'!\n");
129 DisableThreadLibraryCalls(hInstDLL);
131 mod = GetModuleHandleA( "winex11.drv" );
134 wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
135 wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
137 else /* We are most likely on Windows */
139 wine_tsx11_lock_ptr = wined3d_do_nothing;
140 wine_tsx11_unlock_ptr = wined3d_do_nothing;
142 /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
143 if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
145 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
146 if (len && len < MAX_PATH)
149 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
150 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
152 char *p, *appname = buffer;
153 if ((p = strrchr( appname, '/' ))) appname = p + 1;
154 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
155 strcat( appname, "\\Direct3D" );
156 TRACE("appname = [%s]\n", appname);
157 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
158 RegCloseKey( tmpkey );
162 if ( 0 != hkey || 0 != appkey )
164 if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
166 if (!strcmp(buffer,"none"))
168 TRACE("Disable vertex shaders\n");
169 wined3d_settings.vs_mode = VS_NONE;
172 if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
174 if (!strcmp(buffer,"enabled"))
176 TRACE("Allow pixel shaders\n");
177 wined3d_settings.ps_mode = PS_HW;
179 if (!strcmp(buffer,"disabled"))
181 TRACE("Disable pixel shaders\n");
182 wined3d_settings.ps_mode = PS_NONE;
185 if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
187 if (!strcmp(buffer,"none"))
189 TRACE("Disable Vertex Buffer Hardware support\n");
190 wined3d_settings.vbo_mode = VBO_NONE;
192 else if (!strcmp(buffer,"hardware"))
194 TRACE("Allow Vertex Buffer Hardware support\n");
195 wined3d_settings.vbo_mode = VBO_HW;
198 if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
200 if (!strcmp(buffer,"disabled"))
202 TRACE("Use of GL Shading Language disabled\n");
203 wined3d_settings.glslRequested = FALSE;
206 if ( !get_config_key( hkey, appkey, "OffscreenRenderingMode", buffer, size) )
208 if (!strcmp(buffer,"backbuffer"))
210 TRACE("Using the backbuffer for offscreen rendering\n");
211 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
213 else if (!strcmp(buffer,"pbuffer"))
215 TRACE("Using PBuffers for offscreen rendering\n");
216 wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
218 else if (!strcmp(buffer,"fbo"))
220 TRACE("Using FBOs for offscreen rendering\n");
221 wined3d_settings.offscreen_rendering_mode = ORM_FBO;
224 if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
226 if (!strcmp(buffer,"disabled"))
228 TRACE("Disabling render target locking\n");
229 wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
231 else if (!strcmp(buffer,"readdraw"))
233 TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
234 wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
236 else if (!strcmp(buffer,"readtex"))
238 TRACE("Using glReadPixels for render target reading and textures for writing\n");
239 wined3d_settings.rendertargetlock_mode = RTL_READTEX;
241 else if (!strcmp(buffer,"texdraw"))
243 TRACE("Using textures for render target reading and glDrawPixels for writing\n");
244 wined3d_settings.rendertargetlock_mode = RTL_TEXDRAW;
246 else if (!strcmp(buffer,"textex"))
248 TRACE("Reading render targets via textures and writing via textures\n");
249 wined3d_settings.rendertargetlock_mode = RTL_TEXTEX;
252 if ( !get_config_key_dword( hkey, appkey, "VideoPciDeviceID", &tmpvalue) )
254 int pci_device_id = tmpvalue;
256 /* A pci device id is 16-bit */
257 if(pci_device_id > 0xffff)
259 ERR("Invalid value for VideoPciDeviceID. The value should be smaller or equal to 65535 or 0xffff\n");
263 TRACE("Using PCI Device ID %04x\n", pci_device_id);
264 wined3d_settings.pci_device_id = pci_device_id;
267 if ( !get_config_key_dword( hkey, appkey, "VideoPciVendorID", &tmpvalue) )
269 int pci_vendor_id = tmpvalue;
271 /* A pci device id is 16-bit */
272 if(pci_vendor_id > 0xffff)
274 ERR("Invalid value for VideoPciVendorID. The value should be smaller or equal to 65535 or 0xffff\n");
278 TRACE("Using PCI Vendor ID %04x\n", pci_vendor_id);
279 wined3d_settings.pci_vendor_id = pci_vendor_id;
282 if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
284 int TmpVideoMemorySize = atoi(buffer);
285 if(TmpVideoMemorySize > 0)
287 wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
288 TRACE("Use %iMB = %d byte for emulated_textureram\n",
290 wined3d_settings.emulated_textureram);
293 ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
295 if ( !get_config_key( hkey, appkey, "WineLogo", buffer, size) )
297 wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, strlen(buffer) + 1);
298 if(wined3d_settings.logo) strcpy(wined3d_settings.logo, buffer);
300 if ( !get_config_key( hkey, appkey, "Multisampling", buffer, size) )
302 if (!strcmp(buffer,"enabled"))
304 TRACE("Allow multisampling\n");
305 wined3d_settings.allow_multisampling = TRUE;
309 if (wined3d_settings.vs_mode == VS_HW)
310 TRACE("Allow HW vertex shaders\n");
311 if (wined3d_settings.ps_mode == PS_NONE)
312 TRACE("Disable pixel shaders\n");
313 if (wined3d_settings.vbo_mode == VBO_NONE)
314 TRACE("Disable Vertex Buffer Hardware support\n");
315 if (wined3d_settings.glslRequested)
316 TRACE("If supported by your system, GL Shading Language will be used\n");
318 if (appkey) RegCloseKey( appkey );
319 if (hkey) RegCloseKey( hkey );