msi: Make msi_dialog_dup_property return a copy of the property if the property is...
[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     FALSE,          /* Use of GLSL disabled by default */
43     SHADER_ARB,     /* Use ARB vertex programs, when available */
44     SHADER_ARB,     /* Use ARB fragment programs, when available */
45     NP2_NATIVE,     /* Use native NPOT textures, when available */
46     RTL_AUTO,       /* Automatically determine best locking method */
47     64*1024*1024    /* 64MB texture memory by default */
48 };
49
50 WineD3DGlobalStatistics *wineD3DGlobalStatistics = NULL;
51 CRITICAL_SECTION resourceStoreCriticalSection;
52
53 long globalChangeGlRam(long glram){
54     /* FIXME: replace this function with object tracking */
55     int result;
56
57     EnterCriticalSection(&resourceStoreCriticalSection); /* this is overkill really, but I suppose it should be thread safe */
58     wineD3DGlobalStatistics->glsurfaceram     += glram;
59     TRACE("Adjusted gl ram by %ld to %d\n", glram, wineD3DGlobalStatistics->glsurfaceram);
60     result = wineD3DGlobalStatistics->glsurfaceram;
61     LeaveCriticalSection(&resourceStoreCriticalSection);
62     return result;
63
64 }
65
66 IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion, IUnknown *parent) {
67     IWineD3DImpl* object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
68     object->lpVtbl = &IWineD3D_Vtbl;
69     object->dxVersion = dxVersion;
70     object->ref = 1;
71     object->parent = parent;
72
73     /* TODO: Move this off to device and possibly x11drv */
74     /* Create a critical section for a dll global data store */
75     InitializeCriticalSectionAndSpinCount(&resourceStoreCriticalSection, 0x80000400);
76
77     /*Create a structure for storing global data in*/
78     if(wineD3DGlobalStatistics == NULL){
79         TRACE("Createing global statistics store\n");
80         wineD3DGlobalStatistics = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wineD3DGlobalStatistics));
81
82     }
83
84
85     TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
86
87     return (IWineD3D *)object;
88 }
89
90 inline static DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
91 {
92     if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
93     if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
94     return ERROR_FILE_NOT_FOUND;
95 }
96
97 /* At process attach */
98 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
99 {
100     TRACE("WineD3D DLLMain Reason=%d\n", fdwReason);
101     if (fdwReason == DLL_PROCESS_ATTACH)
102     {
103        HMODULE mod;
104        char buffer[MAX_PATH+10];
105        DWORD size = sizeof(buffer);
106        HKEY hkey = 0;
107        HKEY appkey = 0;
108        DWORD len;
109        wined3d_settings.emulated_textureram = 64*1024*1024;
110
111        DisableThreadLibraryCalls(hInstDLL);
112
113        mod = GetModuleHandleA( "winex11.drv" );
114        if (mod)
115        {
116            wine_tsx11_lock_ptr   = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
117            wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
118        }
119        /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
120        if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
121
122        len = GetModuleFileNameA( 0, buffer, MAX_PATH );
123        if (len && len < MAX_PATH)
124        {
125             HKEY tmpkey;
126             /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
127             if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
128             {
129                 char *p, *appname = buffer;
130                 if ((p = strrchr( appname, '/' ))) appname = p + 1;
131                 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
132                 strcat( appname, "\\Direct3D" );
133                 TRACE("appname = [%s]\n", appname);
134                 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
135                 RegCloseKey( tmpkey );
136             }
137        }
138
139        if ( 0 != hkey || 0 != appkey )
140        {
141             if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
142             {
143                 if (!strcmp(buffer,"none"))
144                 {
145                     TRACE("Disable vertex shaders\n");
146                     wined3d_settings.vs_mode = VS_NONE;
147                 }
148                 else if (!strcmp(buffer,"emulation"))
149                 {
150                     TRACE("Force SW vertex shaders\n");
151                     wined3d_settings.vs_mode = VS_SW;
152                 }
153             }
154             if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
155             {
156                 if (!strcmp(buffer,"enabled"))
157                 {
158                     TRACE("Allow pixel shaders\n");
159                     wined3d_settings.ps_mode = PS_HW;
160                 }
161                 if (!strcmp(buffer,"disabled"))
162                 {
163                     TRACE("Disable pixel shaders\n");
164                     wined3d_settings.ps_mode = PS_NONE;
165                 }
166             }
167             if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
168             {
169                 if (!strcmp(buffer,"none"))
170                 {
171                     TRACE("Disable Vertex Buffer Hardware support\n");
172                     wined3d_settings.vbo_mode = VBO_NONE;
173                 }
174                 else if (!strcmp(buffer,"hardware"))
175                 {
176                     TRACE("Allow Vertex Buffer Hardware support\n");
177                     wined3d_settings.vbo_mode = VBO_HW;
178                 }
179             }
180             if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
181             {
182                 if (!strcmp(buffer,"enabled"))
183                 {
184                     TRACE("Use of GL Shading Language enabled for systems that support it\n");
185                     wined3d_settings.glslRequested = TRUE;
186                 }
187                 else
188                 {
189                     TRACE("Use of GL Shading Language disabled\n");
190                 }
191             }
192             if ( !get_config_key( hkey, appkey, "Nonpower2Mode", buffer, size) )
193             {
194                 if (!strcmp(buffer,"none"))
195                 {
196                     TRACE("Using default non-power2 textures\n");
197                     wined3d_settings.nonpower2_mode = NP2_NONE;
198
199                 }
200                 else if (!strcmp(buffer,"repack"))
201                 {
202                     TRACE("Repacking non-power2 textures\n");
203                     wined3d_settings.nonpower2_mode = NP2_REPACK;
204                 }
205                 /* There will be a couple of other choices for nonpow2, they are: TextureRecrangle and OpenGL 2 */
206             }
207             if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
208             {
209                 if (!strcmp(buffer,"disabled"))
210                 {
211                     TRACE("Disabling render target locking\n");
212                     wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
213                 }
214                 else if (!strcmp(buffer,"readdraw"))
215                 {
216                     TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
217                     wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
218                 }
219                 else if (!strcmp(buffer,"readtex"))
220                 {
221                     TRACE("Using glReadPixels for render target reading and textures for writing\n");
222                     wined3d_settings.rendertargetlock_mode = RTL_READTEX;
223                 }
224                 else if (!strcmp(buffer,"texdraw"))
225                 {
226                     TRACE("Using textures for render target reading and glDrawPixels for writing\n");
227                     wined3d_settings.rendertargetlock_mode = RTL_TEXDRAW;
228                 }
229                 else if (!strcmp(buffer,"textex"))
230                 {
231                     TRACE("Reading render targets via textures and writing via textures\n");
232                     wined3d_settings.rendertargetlock_mode = RTL_TEXTEX;
233                 }
234             }
235             if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
236             {
237                 int TmpVideoMemorySize = atoi(buffer);
238                 if(TmpVideoMemorySize > 0)
239                 {
240                     wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
241                     TRACE("Use %iMB = %d byte for emulated_textureram\n",
242                             TmpVideoMemorySize,
243                             wined3d_settings.emulated_textureram);
244                 }
245                 else
246                     ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
247             }
248        }
249        if (wined3d_settings.vs_mode == VS_HW)
250            TRACE("Allow HW vertex shaders\n");
251        if (wined3d_settings.ps_mode == PS_NONE)
252            TRACE("Disable pixel shaders\n");
253        if (wined3d_settings.vbo_mode == VBO_NONE)
254            TRACE("Disable Vertex Buffer Hardware support\n");
255        if (wined3d_settings.glslRequested)
256            TRACE("If supported by your system, GL Shading Language will be used\n");
257        if (wined3d_settings.nonpower2_mode == NP2_REPACK)
258            TRACE("Repacking non-power2 textures\n");
259
260        if (appkey) RegCloseKey( appkey );
261        if (hkey) RegCloseKey( hkey );
262     }
263     return TRUE;
264 }