1 | /*
|
---|
2 | * Direct3D wine internal interface main
|
---|
3 | *
|
---|
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
|
---|
8 | *
|
---|
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.
|
---|
13 | *
|
---|
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.
|
---|
18 | *
|
---|
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
|
---|
22 | */
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
26 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
27 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
28 | * a choice of LGPL license versions is made available with the language indicating
|
---|
29 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
30 | * of the LGPL is applied is otherwise unspecified.
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include "config.h"
|
---|
34 |
|
---|
35 | #include "initguid.h"
|
---|
36 | #include "wined3d_private.h"
|
---|
37 |
|
---|
38 | WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
---|
39 |
|
---|
40 | int num_lock = 0;
|
---|
41 | void (*CDECL wine_tsx11_lock_ptr)(void) = NULL;
|
---|
42 | void (*CDECL wine_tsx11_unlock_ptr)(void) = NULL;
|
---|
43 |
|
---|
44 |
|
---|
45 | /* When updating default value here, make sure to update winecfg as well,
|
---|
46 | * where appropriate. */
|
---|
47 | wined3d_settings_t wined3d_settings =
|
---|
48 | {
|
---|
49 | VS_HW, /* Hardware by default */
|
---|
50 | PS_HW, /* Hardware by default */
|
---|
51 | VBO_HW, /* Hardware by default */
|
---|
52 | TRUE, /* Use of GLSL enabled by default */
|
---|
53 | ORM_BACKBUFFER, /* Use the backbuffer to do offscreen rendering */
|
---|
54 | RTL_AUTO, /* Automatically determine best locking method */
|
---|
55 | PCI_VENDOR_NONE,/* PCI Vendor ID */
|
---|
56 | PCI_DEVICE_NONE,/* PCI Device ID */
|
---|
57 | 0, /* The default of memory is set in FillGLCaps */
|
---|
58 | NULL, /* No wine logo by default */
|
---|
59 | FALSE /* Disable multisampling for now due to Nvidia driver bugs which happens for some users */
|
---|
60 | };
|
---|
61 |
|
---|
62 | IWineD3D* WINAPI WineDirect3DCreate(UINT dxVersion, IUnknown *parent) {
|
---|
63 | IWineD3DImpl* object;
|
---|
64 |
|
---|
65 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
|
---|
66 | object->lpVtbl = &IWineD3D_Vtbl;
|
---|
67 | object->dxVersion = dxVersion;
|
---|
68 | object->ref = 1;
|
---|
69 | object->parent = parent;
|
---|
70 |
|
---|
71 | if (!InitAdapters(object))
|
---|
72 | {
|
---|
73 | WARN("Failed to initialize direct3d adapters, Direct3D will not be available\n");
|
---|
74 | if (dxVersion > 7)
|
---|
75 | {
|
---|
76 | ERR("Direct3D%d is not available without opengl\n", dxVersion);
|
---|
77 | HeapFree(GetProcessHeap(), 0, object);
|
---|
78 | return NULL;
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
|
---|
83 |
|
---|
84 | return (IWineD3D *)object;
|
---|
85 | }
|
---|
86 |
|
---|
87 | static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
|
---|
88 | {
|
---|
89 | if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
|
---|
90 | if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
|
---|
91 | return ERROR_FILE_NOT_FOUND;
|
---|
92 | }
|
---|
93 |
|
---|
94 | static inline DWORD get_config_key_dword(HKEY defkey, HKEY appkey, const char* name, DWORD *data)
|
---|
95 | {
|
---|
96 | DWORD type;
|
---|
97 | DWORD size = sizeof(DWORD);
|
---|
98 | if (0 != appkey && !RegQueryValueExA( appkey, name, 0, &type, (LPBYTE) data, &size ) && (type == REG_DWORD)) return 0;
|
---|
99 | if (0 != defkey && !RegQueryValueExA( defkey, name, 0, &type, (LPBYTE) data, &size ) && (type == REG_DWORD)) return 0;
|
---|
100 | return ERROR_FILE_NOT_FOUND;
|
---|
101 | }
|
---|
102 |
|
---|
103 | static void CDECL wined3d_do_nothing(void)
|
---|
104 | {
|
---|
105 | }
|
---|
106 |
|
---|
107 | static BOOL wined3d_init(HINSTANCE hInstDLL)
|
---|
108 | {
|
---|
109 | HMODULE mod;
|
---|
110 | char buffer[MAX_PATH+10];
|
---|
111 | DWORD size = sizeof(buffer);
|
---|
112 | HKEY hkey = 0;
|
---|
113 | HKEY appkey = 0;
|
---|
114 | DWORD len, tmpvalue;
|
---|
115 | WNDCLASSA wc;
|
---|
116 |
|
---|
117 | /* We need our own window class for a fake window which we use to retrieve GL capabilities */
|
---|
118 | /* We might need CS_OWNDC in the future if we notice strange things on Windows.
|
---|
119 | * Various articles/posts about OpenGL problems on Windows recommend this. */
|
---|
120 | wc.style = CS_HREDRAW | CS_VREDRAW;
|
---|
121 | wc.lpfnWndProc = DefWindowProcA;
|
---|
122 | wc.cbClsExtra = 0;
|
---|
123 | wc.cbWndExtra = 0;
|
---|
124 | wc.hInstance = hInstDLL;
|
---|
125 | wc.hIcon = LoadIconA(NULL, (LPCSTR)IDI_WINLOGO);
|
---|
126 | wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
|
---|
127 | wc.hbrBackground = NULL;
|
---|
128 | wc.lpszMenuName = NULL;
|
---|
129 | wc.lpszClassName = WINED3D_OPENGL_WINDOW_CLASS_NAME;
|
---|
130 |
|
---|
131 | if (!RegisterClassA(&wc))
|
---|
132 | {
|
---|
133 | ERR("Failed to register window class 'WineD3D_OpenGL'!\n");
|
---|
134 | return FALSE;
|
---|
135 | }
|
---|
136 |
|
---|
137 | DisableThreadLibraryCalls(hInstDLL);
|
---|
138 |
|
---|
139 | mod = GetModuleHandleA( "winex11.drv" );
|
---|
140 | if (mod)
|
---|
141 | {
|
---|
142 | wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
|
---|
143 | wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
|
---|
144 | }
|
---|
145 | else /* We are most likely on Windows */
|
---|
146 | {
|
---|
147 | wine_tsx11_lock_ptr = wined3d_do_nothing;
|
---|
148 | wine_tsx11_unlock_ptr = wined3d_do_nothing;
|
---|
149 | }
|
---|
150 | /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
|
---|
151 | if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
|
---|
152 |
|
---|
153 | len = GetModuleFileNameA( 0, buffer, MAX_PATH );
|
---|
154 | if (len && len < MAX_PATH)
|
---|
155 | {
|
---|
156 | HKEY tmpkey;
|
---|
157 | /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
|
---|
158 | if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
|
---|
159 | {
|
---|
160 | char *p, *appname = buffer;
|
---|
161 | if ((p = strrchr( appname, '/' ))) appname = p + 1;
|
---|
162 | if ((p = strrchr( appname, '\\' ))) appname = p + 1;
|
---|
163 | strcat( appname, "\\Direct3D" );
|
---|
164 | TRACE("appname = [%s]\n", appname);
|
---|
165 | if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
|
---|
166 | RegCloseKey( tmpkey );
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | if ( 0 != hkey || 0 != appkey )
|
---|
171 | {
|
---|
172 | if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
|
---|
173 | {
|
---|
174 | if (!strcmp(buffer,"none"))
|
---|
175 | {
|
---|
176 | TRACE("Disable vertex shaders\n");
|
---|
177 | wined3d_settings.vs_mode = VS_NONE;
|
---|
178 | }
|
---|
179 | }
|
---|
180 | if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
|
---|
181 | {
|
---|
182 | if (!strcmp(buffer,"enabled"))
|
---|
183 | {
|
---|
184 | TRACE("Allow pixel shaders\n");
|
---|
185 | wined3d_settings.ps_mode = PS_HW;
|
---|
186 | }
|
---|
187 | if (!strcmp(buffer,"disabled"))
|
---|
188 | {
|
---|
189 | TRACE("Disable pixel shaders\n");
|
---|
190 | wined3d_settings.ps_mode = PS_NONE;
|
---|
191 | }
|
---|
192 | }
|
---|
193 | if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
|
---|
194 | {
|
---|
195 | if (!strcmp(buffer,"none"))
|
---|
196 | {
|
---|
197 | TRACE("Disable Vertex Buffer Hardware support\n");
|
---|
198 | wined3d_settings.vbo_mode = VBO_NONE;
|
---|
199 | }
|
---|
200 | else if (!strcmp(buffer,"hardware"))
|
---|
201 | {
|
---|
202 | TRACE("Allow Vertex Buffer Hardware support\n");
|
---|
203 | wined3d_settings.vbo_mode = VBO_HW;
|
---|
204 | }
|
---|
205 | }
|
---|
206 | if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
|
---|
207 | {
|
---|
208 | if (!strcmp(buffer,"disabled"))
|
---|
209 | {
|
---|
210 | TRACE("Use of GL Shading Language disabled\n");
|
---|
211 | wined3d_settings.glslRequested = FALSE;
|
---|
212 | }
|
---|
213 | }
|
---|
214 | if ( !get_config_key( hkey, appkey, "OffscreenRenderingMode", buffer, size) )
|
---|
215 | {
|
---|
216 | if (!strcmp(buffer,"backbuffer"))
|
---|
217 | {
|
---|
218 | TRACE("Using the backbuffer for offscreen rendering\n");
|
---|
219 | wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
|
---|
220 | }
|
---|
221 | else if (!strcmp(buffer,"pbuffer"))
|
---|
222 | {
|
---|
223 | TRACE("Using PBuffers for offscreen rendering\n");
|
---|
224 | wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
|
---|
225 | }
|
---|
226 | else if (!strcmp(buffer,"fbo"))
|
---|
227 | {
|
---|
228 | TRACE("Using FBOs for offscreen rendering\n");
|
---|
229 | wined3d_settings.offscreen_rendering_mode = ORM_FBO;
|
---|
230 | }
|
---|
231 | }
|
---|
232 | if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
|
---|
233 | {
|
---|
234 | if (!strcmp(buffer,"disabled"))
|
---|
235 | {
|
---|
236 | TRACE("Disabling render target locking\n");
|
---|
237 | wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
|
---|
238 | }
|
---|
239 | else if (!strcmp(buffer,"readdraw"))
|
---|
240 | {
|
---|
241 | TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
|
---|
242 | wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
|
---|
243 | }
|
---|
244 | else if (!strcmp(buffer,"readtex"))
|
---|
245 | {
|
---|
246 | TRACE("Using glReadPixels for render target reading and textures for writing\n");
|
---|
247 | wined3d_settings.rendertargetlock_mode = RTL_READTEX;
|
---|
248 | }
|
---|
249 | else if (!strcmp(buffer,"texdraw"))
|
---|
250 | {
|
---|
251 | TRACE("Using textures for render target reading and glDrawPixels for writing\n");
|
---|
252 | wined3d_settings.rendertargetlock_mode = RTL_TEXDRAW;
|
---|
253 | }
|
---|
254 | else if (!strcmp(buffer,"textex"))
|
---|
255 | {
|
---|
256 | TRACE("Reading render targets via textures and writing via textures\n");
|
---|
257 | wined3d_settings.rendertargetlock_mode = RTL_TEXTEX;
|
---|
258 | }
|
---|
259 | }
|
---|
260 | if ( !get_config_key_dword( hkey, appkey, "VideoPciDeviceID", &tmpvalue) )
|
---|
261 | {
|
---|
262 | int pci_device_id = tmpvalue;
|
---|
263 |
|
---|
264 | /* A pci device id is 16-bit */
|
---|
265 | if(pci_device_id > 0xffff)
|
---|
266 | {
|
---|
267 | ERR("Invalid value for VideoPciDeviceID. The value should be smaller or equal to 65535 or 0xffff\n");
|
---|
268 | }
|
---|
269 | else
|
---|
270 | {
|
---|
271 | TRACE("Using PCI Device ID %04x\n", pci_device_id);
|
---|
272 | wined3d_settings.pci_device_id = pci_device_id;
|
---|
273 | }
|
---|
274 | }
|
---|
275 | if ( !get_config_key_dword( hkey, appkey, "VideoPciVendorID", &tmpvalue) )
|
---|
276 | {
|
---|
277 | int pci_vendor_id = tmpvalue;
|
---|
278 |
|
---|
279 | /* A pci device id is 16-bit */
|
---|
280 | if(pci_vendor_id > 0xffff)
|
---|
281 | {
|
---|
282 | ERR("Invalid value for VideoPciVendorID. The value should be smaller or equal to 65535 or 0xffff\n");
|
---|
283 | }
|
---|
284 | else
|
---|
285 | {
|
---|
286 | TRACE("Using PCI Vendor ID %04x\n", pci_vendor_id);
|
---|
287 | wined3d_settings.pci_vendor_id = pci_vendor_id;
|
---|
288 | }
|
---|
289 | }
|
---|
290 | if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
|
---|
291 | {
|
---|
292 | int TmpVideoMemorySize = atoi(buffer);
|
---|
293 | if(TmpVideoMemorySize > 0)
|
---|
294 | {
|
---|
295 | wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
|
---|
296 | TRACE("Use %iMB = %d byte for emulated_textureram\n",
|
---|
297 | TmpVideoMemorySize,
|
---|
298 | wined3d_settings.emulated_textureram);
|
---|
299 | }
|
---|
300 | else
|
---|
301 | ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
|
---|
302 | }
|
---|
303 | if ( !get_config_key( hkey, appkey, "WineLogo", buffer, size) )
|
---|
304 | {
|
---|
305 | wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, strlen(buffer) + 1);
|
---|
306 | if(wined3d_settings.logo) strcpy(wined3d_settings.logo, buffer);
|
---|
307 | }
|
---|
308 | if ( !get_config_key( hkey, appkey, "Multisampling", buffer, size) )
|
---|
309 | {
|
---|
310 | if (!strcmp(buffer,"enabled"))
|
---|
311 | {
|
---|
312 | TRACE("Allow multisampling\n");
|
---|
313 | wined3d_settings.allow_multisampling = TRUE;
|
---|
314 | }
|
---|
315 | }
|
---|
316 | }
|
---|
317 | if (wined3d_settings.vs_mode == VS_HW)
|
---|
318 | TRACE("Allow HW vertex shaders\n");
|
---|
319 | if (wined3d_settings.ps_mode == PS_NONE)
|
---|
320 | TRACE("Disable pixel shaders\n");
|
---|
321 | if (wined3d_settings.vbo_mode == VBO_NONE)
|
---|
322 | TRACE("Disable Vertex Buffer Hardware support\n");
|
---|
323 | if (wined3d_settings.glslRequested)
|
---|
324 | TRACE("If supported by your system, GL Shading Language will be used\n");
|
---|
325 |
|
---|
326 | if (appkey) RegCloseKey( appkey );
|
---|
327 | if (hkey) RegCloseKey( hkey );
|
---|
328 |
|
---|
329 | return TRUE;
|
---|
330 | }
|
---|
331 |
|
---|
332 | static BOOL wined3d_destroy(HINSTANCE hInstDLL)
|
---|
333 | {
|
---|
334 | HeapFree(GetProcessHeap(), 0, wined3d_settings.logo);
|
---|
335 | UnregisterClassA(WINED3D_OPENGL_WINDOW_CLASS_NAME, hInstDLL);
|
---|
336 |
|
---|
337 | return TRUE;
|
---|
338 | }
|
---|
339 |
|
---|
340 | /* At process attach */
|
---|
341 | BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
|
---|
342 | {
|
---|
343 | TRACE("WineD3D DLLMain Reason=%u\n", fdwReason);
|
---|
344 |
|
---|
345 | switch (fdwReason)
|
---|
346 | {
|
---|
347 | case DLL_PROCESS_ATTACH:
|
---|
348 | return wined3d_init(hInstDLL);
|
---|
349 |
|
---|
350 | case DLL_PROCESS_DETACH:
|
---|
351 | return wined3d_destroy(hInstDLL);
|
---|
352 |
|
---|
353 | default:
|
---|
354 | return TRUE;
|
---|
355 | }
|
---|
356 | }
|
---|