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