browseui: Make a function static.
[wine] / dlls / wined3d / wined3d_main.c
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 #include "config.h"
25
26 #include "initguid.h"
27 #include "wined3d_private.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
30
31 int num_lock = 0;
32 void (*wine_tsx11_lock_ptr)(void) = NULL;
33 void (*wine_tsx11_unlock_ptr)(void) = NULL;
34
35
36 /* When updating default value here, make sure to update winecfg as well,
37  * where appropriate. */
38 wined3d_settings_t wined3d_settings = 
39 {
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 */
51 };
52
53 IWineD3D* WINAPI WineDirect3DCreate(UINT dxVersion, IUnknown *parent) {
54     IWineD3DImpl* object;
55
56     if (!InitAdapters()) {
57         WARN("Failed to initialize direct3d adapters, Direct3D will not be available\n");
58         if(dxVersion > 7) {
59             ERR("Direct3D%d is not available without opengl\n", dxVersion);
60             return NULL;
61         }
62     }
63
64     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
65     object->lpVtbl = &IWineD3D_Vtbl;
66     object->dxVersion = dxVersion;
67     object->ref = 1;
68     object->parent = parent;
69
70     TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
71
72     return (IWineD3D *)object;
73 }
74
75 static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
76 {
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;
80 }
81
82 static inline DWORD get_config_key_dword(HKEY defkey, HKEY appkey, const char* name, DWORD *data)
83 {
84     DWORD type;
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;
89 }
90
91 static void wined3d_do_nothing(void)
92 {
93 }
94
95 /* At process attach */
96 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
97 {
98     TRACE("WineD3D DLLMain Reason=%d\n", fdwReason);
99     if (fdwReason == DLL_PROCESS_ATTACH)
100     {
101        HMODULE mod;
102        char buffer[MAX_PATH+10];
103        DWORD size = sizeof(buffer);
104        HKEY hkey = 0;
105        HKEY appkey = 0;
106        DWORD len, tmpvalue;
107        WNDCLASSA wc;
108
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;
114        wc.cbClsExtra           = 0;
115        wc.cbWndExtra           = 0;
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";
122
123        if (!RegisterClassA(&wc) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
124        {
125            ERR("Failed to register window class 'WineD3D_OpenGL'!\n");
126            return FALSE;
127        }
128
129        DisableThreadLibraryCalls(hInstDLL);
130
131        mod = GetModuleHandleA( "winex11.drv" );
132        if (mod)
133        {
134            wine_tsx11_lock_ptr   = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
135            wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
136        }
137        else /* We are most likely on Windows */
138        {
139            wine_tsx11_lock_ptr   = wined3d_do_nothing;
140            wine_tsx11_unlock_ptr = wined3d_do_nothing;
141        }
142        /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
143        if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
144
145        len = GetModuleFileNameA( 0, buffer, MAX_PATH );
146        if (len && len < MAX_PATH)
147        {
148             HKEY tmpkey;
149             /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
150             if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
151             {
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 );
159             }
160        }
161
162        if ( 0 != hkey || 0 != appkey )
163        {
164             if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
165             {
166                 if (!strcmp(buffer,"none"))
167                 {
168                     TRACE("Disable vertex shaders\n");
169                     wined3d_settings.vs_mode = VS_NONE;
170                 }
171             }
172             if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
173             {
174                 if (!strcmp(buffer,"enabled"))
175                 {
176                     TRACE("Allow pixel shaders\n");
177                     wined3d_settings.ps_mode = PS_HW;
178                 }
179                 if (!strcmp(buffer,"disabled"))
180                 {
181                     TRACE("Disable pixel shaders\n");
182                     wined3d_settings.ps_mode = PS_NONE;
183                 }
184             }
185             if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
186             {
187                 if (!strcmp(buffer,"none"))
188                 {
189                     TRACE("Disable Vertex Buffer Hardware support\n");
190                     wined3d_settings.vbo_mode = VBO_NONE;
191                 }
192                 else if (!strcmp(buffer,"hardware"))
193                 {
194                     TRACE("Allow Vertex Buffer Hardware support\n");
195                     wined3d_settings.vbo_mode = VBO_HW;
196                 }
197             }
198             if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
199             {
200                 if (!strcmp(buffer,"disabled"))
201                 {
202                     TRACE("Use of GL Shading Language disabled\n");
203                     wined3d_settings.glslRequested = FALSE;
204                 }
205             }
206             if ( !get_config_key( hkey, appkey, "OffscreenRenderingMode", buffer, size) )
207             {
208                 if (!strcmp(buffer,"backbuffer"))
209                 {
210                     TRACE("Using the backbuffer for offscreen rendering\n");
211                     wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
212                 }
213                 else if (!strcmp(buffer,"pbuffer"))
214                 {
215                     TRACE("Using PBuffers for offscreen rendering\n");
216                     wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
217                 }
218                 else if (!strcmp(buffer,"fbo"))
219                 {
220                     TRACE("Using FBOs for offscreen rendering\n");
221                     wined3d_settings.offscreen_rendering_mode = ORM_FBO;
222                 }
223             }
224             if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
225             {
226                 if (!strcmp(buffer,"disabled"))
227                 {
228                     TRACE("Disabling render target locking\n");
229                     wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
230                 }
231                 else if (!strcmp(buffer,"readdraw"))
232                 {
233                     TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
234                     wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
235                 }
236                 else if (!strcmp(buffer,"readtex"))
237                 {
238                     TRACE("Using glReadPixels for render target reading and textures for writing\n");
239                     wined3d_settings.rendertargetlock_mode = RTL_READTEX;
240                 }
241                 else if (!strcmp(buffer,"texdraw"))
242                 {
243                     TRACE("Using textures for render target reading and glDrawPixels for writing\n");
244                     wined3d_settings.rendertargetlock_mode = RTL_TEXDRAW;
245                 }
246                 else if (!strcmp(buffer,"textex"))
247                 {
248                     TRACE("Reading render targets via textures and writing via textures\n");
249                     wined3d_settings.rendertargetlock_mode = RTL_TEXTEX;
250                 }
251             }
252             if ( !get_config_key_dword( hkey, appkey, "VideoPciDeviceID", &tmpvalue) )
253             {
254                 int pci_device_id = tmpvalue;
255
256                 /* A pci device id is 16-bit */
257                 if(pci_device_id > 0xffff)
258                 {
259                     ERR("Invalid value for VideoPciDeviceID. The value should be smaller or equal to 65535 or 0xffff\n");
260                 }
261                 else
262                 {
263                     TRACE("Using PCI Device ID %04x\n", pci_device_id);
264                     wined3d_settings.pci_device_id = pci_device_id;
265                 }
266             }
267             if ( !get_config_key_dword( hkey, appkey, "VideoPciVendorID", &tmpvalue) )
268             {
269                 int pci_vendor_id = tmpvalue;
270
271                 /* A pci device id is 16-bit */
272                 if(pci_vendor_id > 0xffff)
273                 {
274                     ERR("Invalid value for VideoPciVendorID. The value should be smaller or equal to 65535 or 0xffff\n");
275                 }
276                 else
277                 {
278                     TRACE("Using PCI Vendor ID %04x\n", pci_vendor_id);
279                     wined3d_settings.pci_vendor_id = pci_vendor_id;
280                 }
281             }
282             if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
283             {
284                 int TmpVideoMemorySize = atoi(buffer);
285                 if(TmpVideoMemorySize > 0)
286                 {
287                     wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
288                     TRACE("Use %iMB = %d byte for emulated_textureram\n",
289                             TmpVideoMemorySize,
290                             wined3d_settings.emulated_textureram);
291                 }
292                 else
293                     ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
294             }
295             if ( !get_config_key( hkey, appkey, "WineLogo", buffer, size) )
296             {
297                 wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, strlen(buffer) + 1);
298                 if(wined3d_settings.logo) strcpy(wined3d_settings.logo, buffer);
299             }
300             if ( !get_config_key( hkey, appkey, "Multisampling", buffer, size) )
301             {
302                 if (!strcmp(buffer,"enabled"))
303                 {
304                     TRACE("Allow multisampling\n");
305                     wined3d_settings.allow_multisampling = TRUE;
306                 }
307             }
308        }
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");
317
318        if (appkey) RegCloseKey( appkey );
319        if (hkey) RegCloseKey( hkey );
320     }
321     return TRUE;
322 }