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