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 (*wine_tsx11_lock_ptr)(void) = NULL;
|
---|
42 | void (*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 | if (!InitAdapters()) {
|
---|
66 | WARN("Failed to initialize direct3d adapters, Direct3D will not be available\n");
|
---|
67 | if(dxVersion > 7) {
|
---|
68 | ERR("Direct3D%d is not available without opengl\n", dxVersion);
|
---|
69 | return NULL;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
|
---|
74 | object->lpVtbl = &IWineD3D_Vtbl;
|
---|
75 | object->dxVersion = dxVersion;
|
---|
76 | object->ref = 1;
|
---|
77 | object->parent = parent;
|
---|
78 |
|
---|
79 | TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
|
---|
80 |
|
---|
81 | return (IWineD3D *)object;
|
---|
82 | }
|
---|
83 |
|
---|
84 | static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
|
---|
85 | {
|
---|
86 | if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
|
---|
87 | if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
|
---|
88 | return ERROR_FILE_NOT_FOUND;
|
---|
89 | }
|
---|
90 |
|
---|
91 | static inline DWORD get_config_key_dword(HKEY defkey, HKEY appkey, const char* name, DWORD *data)
|
---|
92 | {
|
---|
93 | DWORD type;
|
---|
94 | DWORD size = sizeof(DWORD);
|
---|
95 | if (0 != appkey && !RegQueryValueExA( appkey, name, 0, &type, (LPBYTE) data, &size ) && (type == REG_DWORD)) return 0;
|
---|
96 | if (0 != defkey && !RegQueryValueExA( defkey, name, 0, &type, (LPBYTE) data, &size ) && (type == REG_DWORD)) return 0;
|
---|
97 | return ERROR_FILE_NOT_FOUND;
|
---|
98 | }
|
---|
99 |
|
---|
100 | static void wined3d_do_nothing(void)
|
---|
101 | {
|
---|
102 | }
|
---|
103 |
|
---|
104 | /* At process attach */
|
---|
105 | BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
|
---|
106 | {
|
---|
107 | TRACE("WineD3D DLLMain Reason=%d\n", fdwReason);
|
---|
108 | if (fdwReason == DLL_PROCESS_ATTACH)
|
---|
109 | {
|
---|
110 | HMODULE mod;
|
---|
111 | char buffer[MAX_PATH+10];
|
---|
112 | DWORD size = sizeof(buffer);
|
---|
113 | HKEY hkey = 0;
|
---|
114 | HKEY appkey = 0;
|
---|
115 | DWORD len, tmpvalue;
|
---|
116 | WNDCLASSA wc;
|
---|
117 |
|
---|
118 | /* We need our own window class for a fake window which we use to retrieve GL capabilities */
|
---|
119 | /* We might need CS_OWNDC in the future if we notice strange things on Windows.
|
---|
120 | * Various articles/posts about OpenGL problems on Windows recommend this. */
|
---|
121 | wc.style = CS_HREDRAW | CS_VREDRAW;
|
---|
122 | wc.lpfnWndProc = DefWindowProcA;
|
---|
123 | wc.cbClsExtra = 0;
|
---|
124 | wc.cbWndExtra = 0;
|
---|
125 | wc.hInstance = hInstDLL;
|
---|
126 | wc.hIcon = LoadIconA(NULL, (LPCSTR)IDI_WINLOGO);
|
---|
127 | wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
|
---|
128 | wc.hbrBackground = NULL;
|
---|
129 | wc.lpszMenuName = NULL;
|
---|
130 | wc.lpszClassName = "WineD3D_OpenGL";
|
---|
131 |
|
---|
132 | if (!RegisterClassA(&wc) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
|
---|
133 | {
|
---|
134 | ERR("Failed to register window class 'WineD3D_OpenGL'!\n");
|
---|
135 | return FALSE;
|
---|
136 | }
|
---|
137 |
|
---|
138 | DisableThreadLibraryCalls(hInstDLL);
|
---|
139 |
|
---|
140 | mod = GetModuleHandleA( "winex11.drv" );
|
---|
141 | if (mod)
|
---|
142 | {
|
---|
143 | wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
|
---|
144 | wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
|
---|
145 | }
|
---|
146 | else /* We are most likely on Windows */
|
---|
147 | {
|
---|
148 | wine_tsx11_lock_ptr = wined3d_do_nothing;
|
---|
149 | wine_tsx11_unlock_ptr = wined3d_do_nothing;
|
---|
150 | }
|
---|
151 | /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
|
---|
152 | if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
|
---|
153 |
|
---|
154 | len = GetModuleFileNameA( 0, buffer, MAX_PATH );
|
---|
155 | if (len && len < MAX_PATH)
|
---|
156 | {
|
---|
157 | HKEY tmpkey;
|
---|
158 | /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
|
---|
159 | if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
|
---|
160 | {
|
---|
161 | char *p, *appname = buffer;
|
---|
162 | if ((p = strrchr( appname, '/' ))) appname = p + 1;
|
---|
163 | if ((p = strrchr( appname, '\\' ))) appname = p + 1;
|
---|
164 | strcat( appname, "\\Direct3D" );
|
---|
165 | TRACE("appname = [%s]\n", appname);
|
---|
166 | if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
|
---|
167 | RegCloseKey( tmpkey );
|
---|
168 | }
|
---|
169 | }
|
---|
170 |
|
---|
171 | if ( 0 != hkey || 0 != appkey )
|
---|
172 | {
|
---|
173 | if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
|
---|
174 | {
|
---|
175 | if (!strcmp(buffer,"none"))
|
---|
176 | {
|
---|
177 | TRACE("Disable vertex shaders\n");
|
---|
178 | wined3d_settings.vs_mode = VS_NONE;
|
---|
179 | }
|
---|
180 | }
|
---|
181 | if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
|
---|
182 | {
|
---|
183 | if (!strcmp(buffer,"enabled"))
|
---|
184 | {
|
---|
185 | TRACE("Allow pixel shaders\n");
|
---|
186 | wined3d_settings.ps_mode = PS_HW;
|
---|
187 | }
|
---|
188 | if (!strcmp(buffer,"disabled"))
|
---|
189 | {
|
---|
190 | TRACE("Disable pixel shaders\n");
|
---|
191 | wined3d_settings.ps_mode = PS_NONE;
|
---|
192 | }
|
---|
193 | }
|
---|
194 | if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
|
---|
195 | {
|
---|
196 | if (!strcmp(buffer,"none"))
|
---|
197 | {
|
---|
198 | TRACE("Disable Vertex Buffer Hardware support\n");
|
---|
199 | wined3d_settings.vbo_mode = VBO_NONE;
|
---|
200 | }
|
---|
201 | else if (!strcmp(buffer,"hardware"))
|
---|
202 | {
|
---|
203 | TRACE("Allow Vertex Buffer Hardware support\n");
|
---|
204 | wined3d_settings.vbo_mode = VBO_HW;
|
---|
205 | }
|
---|
206 | }
|
---|
207 | if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
|
---|
208 | {
|
---|
209 | if (!strcmp(buffer,"disabled"))
|
---|
210 | {
|
---|
211 | TRACE("Use of GL Shading Language disabled\n");
|
---|
212 | wined3d_settings.glslRequested = FALSE;
|
---|
213 | }
|
---|
214 | }
|
---|
215 | if ( !get_config_key( hkey, appkey, "OffscreenRenderingMode", buffer, size) )
|
---|
216 | {
|
---|
217 | if (!strcmp(buffer,"backbuffer"))
|
---|
218 | {
|
---|
219 | TRACE("Using the backbuffer for offscreen rendering\n");
|
---|
220 | wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
|
---|
221 | }
|
---|
222 | else if (!strcmp(buffer,"pbuffer"))
|
---|
223 | {
|
---|
224 | TRACE("Using PBuffers for offscreen rendering\n");
|
---|
225 | wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
|
---|
226 | }
|
---|
227 | else if (!strcmp(buffer,"fbo"))
|
---|
228 | {
|
---|
229 | TRACE("Using FBOs for offscreen rendering\n");
|
---|
230 | wined3d_settings.offscreen_rendering_mode = ORM_FBO;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
|
---|
234 | {
|
---|
235 | if (!strcmp(buffer,"disabled"))
|
---|
236 | {
|
---|
237 | TRACE("Disabling render target locking\n");
|
---|
238 | wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
|
---|
239 | }
|
---|
240 | else if (!strcmp(buffer,"readdraw"))
|
---|
241 | {
|
---|
242 | TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
|
---|
243 | wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
|
---|
244 | }
|
---|
245 | else if (!strcmp(buffer,"readtex"))
|
---|
246 | {
|
---|
247 | TRACE("Using glReadPixels for render target reading and textures for writing\n");
|
---|
248 | wined3d_settings.rendertargetlock_mode = RTL_READTEX;
|
---|
249 | }
|
---|
250 | else if (!strcmp(buffer,"texdraw"))
|
---|
251 | {
|
---|
252 | TRACE("Using textures for render target reading and glDrawPixels for writing\n");
|
---|
253 | wined3d_settings.rendertargetlock_mode = RTL_TEXDRAW;
|
---|
254 | }
|
---|
255 | else if (!strcmp(buffer,"textex"))
|
---|
256 | {
|
---|
257 | TRACE("Reading render targets via textures and writing via textures\n");
|
---|
258 | wined3d_settings.rendertargetlock_mode = RTL_TEXTEX;
|
---|
259 | }
|
---|
260 | }
|
---|
261 | if ( !get_config_key_dword( hkey, appkey, "VideoPciDeviceID", &tmpvalue) )
|
---|
262 | {
|
---|
263 | int pci_device_id = tmpvalue;
|
---|
264 |
|
---|
265 | /* A pci device id is 16-bit */
|
---|
266 | if(pci_device_id > 0xffff)
|
---|
267 | {
|
---|
268 | ERR("Invalid value for VideoPciDeviceID. The value should be smaller or equal to 65535 or 0xffff\n");
|
---|
269 | }
|
---|
270 | else
|
---|
271 | {
|
---|
272 | TRACE("Using PCI Device ID %04x\n", pci_device_id);
|
---|
273 | wined3d_settings.pci_device_id = pci_device_id;
|
---|
274 | }
|
---|
275 | }
|
---|
276 | if ( !get_config_key_dword( hkey, appkey, "VideoPciVendorID", &tmpvalue) )
|
---|
277 | {
|
---|
278 | int pci_vendor_id = tmpvalue;
|
---|
279 |
|
---|
280 | /* A pci device id is 16-bit */
|
---|
281 | if(pci_vendor_id > 0xffff)
|
---|
282 | {
|
---|
283 | ERR("Invalid value for VideoPciVendorID. The value should be smaller or equal to 65535 or 0xffff\n");
|
---|
284 | }
|
---|
285 | else
|
---|
286 | {
|
---|
287 | TRACE("Using PCI Vendor ID %04x\n", pci_vendor_id);
|
---|
288 | wined3d_settings.pci_vendor_id = pci_vendor_id;
|
---|
289 | }
|
---|
290 | }
|
---|
291 | if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
|
---|
292 | {
|
---|
293 | int TmpVideoMemorySize = atoi(buffer);
|
---|
294 | if(TmpVideoMemorySize > 0)
|
---|
295 | {
|
---|
296 | wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
|
---|
297 | TRACE("Use %iMB = %d byte for emulated_textureram\n",
|
---|
298 | TmpVideoMemorySize,
|
---|
299 | wined3d_settings.emulated_textureram);
|
---|
300 | }
|
---|
301 | else
|
---|
302 | ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
|
---|
303 | }
|
---|
304 | if ( !get_config_key( hkey, appkey, "WineLogo", buffer, size) )
|
---|
305 | {
|
---|
306 | wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, strlen(buffer) + 1);
|
---|
307 | if(wined3d_settings.logo) strcpy(wined3d_settings.logo, buffer);
|
---|
308 | }
|
---|
309 | if ( !get_config_key( hkey, appkey, "Multisampling", buffer, size) )
|
---|
310 | {
|
---|
311 | if (!strcmp(buffer,"enabled"))
|
---|
312 | {
|
---|
313 | TRACE("Allow multisampling\n");
|
---|
314 | wined3d_settings.allow_multisampling = TRUE;
|
---|
315 | }
|
---|
316 | }
|
---|
317 | }
|
---|
318 | if (wined3d_settings.vs_mode == VS_HW)
|
---|
319 | TRACE("Allow HW vertex shaders\n");
|
---|
320 | if (wined3d_settings.ps_mode == PS_NONE)
|
---|
321 | TRACE("Disable pixel shaders\n");
|
---|
322 | if (wined3d_settings.vbo_mode == VBO_NONE)
|
---|
323 | TRACE("Disable Vertex Buffer Hardware support\n");
|
---|
324 | if (wined3d_settings.glslRequested)
|
---|
325 | TRACE("If supported by your system, GL Shading Language will be used\n");
|
---|
326 |
|
---|
327 | if (appkey) RegCloseKey( appkey );
|
---|
328 | if (hkey) RegCloseKey( hkey );
|
---|
329 | }
|
---|
330 | return TRUE;
|
---|
331 | }
|
---|