advapi32: Create MachineGuid value if it doesn't exist.
[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  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include "config.h"
24
25 #include "initguid.h"
26 #include "wined3d_private.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(wine_d3d);
29
30 int num_lock = 0;
31 void (*wine_tsx11_lock_ptr)(void) = NULL;
32 void (*wine_tsx11_unlock_ptr)(void) = NULL;
33
34
35 /* When updating default value here, make sure to update winecfg as well,
36  * where appropriate. */
37 wined3d_settings_t wined3d_settings = 
38 {
39     VS_HW,          /* Hardware by default */
40     PS_HW,          /* Hardware by default */
41     VBO_HW,         /* Hardware by default */
42     TRUE,           /* Use of GLSL enabled by default */
43     ORM_BACKBUFFER, /* Use the backbuffer to do offscreen rendering */
44     RTL_AUTO,       /* Automatically determine best locking method */
45     0,              /* The default of memory is set in FillGLCaps */
46     NULL            /* No wine logo by default */
47 };
48
49 IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion, IUnknown *parent) {
50     IWineD3DImpl* object;
51
52     if (!InitAdapters()) {
53         WARN("Failed to initialize direct3d adapters, Direct3D will not be available\n");
54         if(dxVersion > 7) {
55             ERR("Direct3D%d is not available without opengl\n", dxVersion);
56             return NULL;
57         }
58     }
59
60     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
61     object->lpVtbl = &IWineD3D_Vtbl;
62     object->dxVersion = dxVersion;
63     object->ref = 1;
64     object->parent = parent;
65
66     TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
67
68     return (IWineD3D *)object;
69 }
70
71 static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
72 {
73     if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
74     if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
75     return ERROR_FILE_NOT_FOUND;
76 }
77
78 static void wined3d_do_nothing(void)
79 {
80 }
81
82 /* At process attach */
83 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
84 {
85     TRACE("WineD3D DLLMain Reason=%d\n", fdwReason);
86     if (fdwReason == DLL_PROCESS_ATTACH)
87     {
88        HMODULE mod;
89        char buffer[MAX_PATH+10];
90        DWORD size = sizeof(buffer);
91        HKEY hkey = 0;
92        HKEY appkey = 0;
93        DWORD len;
94        WNDCLASSA wc;
95
96        atifs_shader_backend.shader_dll_load_init();
97        glsl_shader_backend.shader_dll_load_init();
98        arb_program_shader_backend.shader_dll_load_init();
99        none_shader_backend.shader_dll_load_init();
100
101        /* We need our own window class for a fake window which we use to retrieve GL capabilities */
102        /* We might need CS_OWNDC in the future if we notice strange things on Windows.
103         * Various articles/posts about OpenGL problems on Windows recommend this. */
104        wc.style                = CS_HREDRAW | CS_VREDRAW;
105        wc.lpfnWndProc          = DefWindowProcA;
106        wc.cbClsExtra           = 0;
107        wc.cbWndExtra           = 0;
108        wc.hInstance            = hInstDLL;
109        wc.hIcon                = LoadIconA(NULL, (LPCSTR)IDI_WINLOGO);
110        wc.hCursor              = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
111        wc.hbrBackground        = NULL;
112        wc.lpszMenuName         = NULL;
113        wc.lpszClassName        = "WineD3D_OpenGL";
114
115        if (!RegisterClassA(&wc) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
116        {
117            ERR("Failed to register window class 'WineD3D_OpenGL'!\n");
118            return FALSE;
119        }
120
121        DisableThreadLibraryCalls(hInstDLL);
122
123        mod = GetModuleHandleA( "winex11.drv" );
124        if (mod)
125        {
126            wine_tsx11_lock_ptr   = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
127            wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
128        }
129        else /* We are most likely on Windows */
130        {
131            wine_tsx11_lock_ptr   = wined3d_do_nothing;
132            wine_tsx11_unlock_ptr = wined3d_do_nothing;
133        }
134        /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
135        if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
136
137        len = GetModuleFileNameA( 0, buffer, MAX_PATH );
138        if (len && len < MAX_PATH)
139        {
140             HKEY tmpkey;
141             /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
142             if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
143             {
144                 char *p, *appname = buffer;
145                 if ((p = strrchr( appname, '/' ))) appname = p + 1;
146                 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
147                 strcat( appname, "\\Direct3D" );
148                 TRACE("appname = [%s]\n", appname);
149                 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
150                 RegCloseKey( tmpkey );
151             }
152        }
153
154        if ( 0 != hkey || 0 != appkey )
155        {
156             if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
157             {
158                 if (!strcmp(buffer,"none"))
159                 {
160                     TRACE("Disable vertex shaders\n");
161                     wined3d_settings.vs_mode = VS_NONE;
162                 }
163             }
164             if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
165             {
166                 if (!strcmp(buffer,"enabled"))
167                 {
168                     TRACE("Allow pixel shaders\n");
169                     wined3d_settings.ps_mode = PS_HW;
170                 }
171                 if (!strcmp(buffer,"disabled"))
172                 {
173                     TRACE("Disable pixel shaders\n");
174                     wined3d_settings.ps_mode = PS_NONE;
175                 }
176             }
177             if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
178             {
179                 if (!strcmp(buffer,"none"))
180                 {
181                     TRACE("Disable Vertex Buffer Hardware support\n");
182                     wined3d_settings.vbo_mode = VBO_NONE;
183                 }
184                 else if (!strcmp(buffer,"hardware"))
185                 {
186                     TRACE("Allow Vertex Buffer Hardware support\n");
187                     wined3d_settings.vbo_mode = VBO_HW;
188                 }
189             }
190             if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
191             {
192                 if (!strcmp(buffer,"disabled"))
193                 {
194                     TRACE("Use of GL Shading Language disabled\n");
195                     wined3d_settings.glslRequested = FALSE;
196                 }
197             }
198             if ( !get_config_key( hkey, appkey, "OffscreenRenderingMode", buffer, size) )
199             {
200                 if (!strcmp(buffer,"backbuffer"))
201                 {
202                     TRACE("Using the backbuffer for offscreen rendering\n");
203                     wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
204                 }
205                 else if (!strcmp(buffer,"pbuffer"))
206                 {
207                     TRACE("Using PBuffers for offscreen rendering\n");
208                     wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
209                 }
210                 else if (!strcmp(buffer,"fbo"))
211                 {
212                     TRACE("Using FBOs for offscreen rendering\n");
213                     wined3d_settings.offscreen_rendering_mode = ORM_FBO;
214                 }
215             }
216             if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
217             {
218                 if (!strcmp(buffer,"disabled"))
219                 {
220                     TRACE("Disabling render target locking\n");
221                     wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
222                 }
223                 else if (!strcmp(buffer,"readdraw"))
224                 {
225                     TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
226                     wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
227                 }
228                 else if (!strcmp(buffer,"readtex"))
229                 {
230                     TRACE("Using glReadPixels for render target reading and textures for writing\n");
231                     wined3d_settings.rendertargetlock_mode = RTL_READTEX;
232                 }
233                 else if (!strcmp(buffer,"texdraw"))
234                 {
235                     TRACE("Using textures for render target reading and glDrawPixels for writing\n");
236                     wined3d_settings.rendertargetlock_mode = RTL_TEXDRAW;
237                 }
238                 else if (!strcmp(buffer,"textex"))
239                 {
240                     TRACE("Reading render targets via textures and writing via textures\n");
241                     wined3d_settings.rendertargetlock_mode = RTL_TEXTEX;
242                 }
243             }
244             if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
245             {
246                 int TmpVideoMemorySize = atoi(buffer);
247                 if(TmpVideoMemorySize > 0)
248                 {
249                     wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
250                     TRACE("Use %iMB = %d byte for emulated_textureram\n",
251                             TmpVideoMemorySize,
252                             wined3d_settings.emulated_textureram);
253                 }
254                 else
255                     ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
256             }
257             if ( !get_config_key( hkey, appkey, "WineLogo", buffer, size) )
258             {
259                 wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, strlen(buffer) + 1);
260                 if(wined3d_settings.logo) strcpy(wined3d_settings.logo, buffer);
261             }
262        }
263        if (wined3d_settings.vs_mode == VS_HW)
264            TRACE("Allow HW vertex shaders\n");
265        if (wined3d_settings.ps_mode == PS_NONE)
266            TRACE("Disable pixel shaders\n");
267        if (wined3d_settings.vbo_mode == VBO_NONE)
268            TRACE("Disable Vertex Buffer Hardware support\n");
269        if (wined3d_settings.glslRequested)
270            TRACE("If supported by your system, GL Shading Language will be used\n");
271
272        if (appkey) RegCloseKey( appkey );
273        if (hkey) RegCloseKey( hkey );
274     }
275     return TRUE;
276 }