rpcrt4: Fix the argument size of conformant arrays.
[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 wined3d_settings_t wined3d_settings = 
36 {
37   VS_HW,   /* Hardware by default */
38   PS_NONE, /* Disabled by default */
39   VBO_HW,   /* Hardware by default */
40   FALSE    /* Use of GLSL disabled by default */
41 };
42
43 WineD3DGlobalStatistics *wineD3DGlobalStatistics = NULL;
44 CRITICAL_SECTION resourceStoreCriticalSection;
45
46 long globalChangeGlRam(long glram){
47     /* FIXME: replace this function with object tracking */
48     int result;
49
50     EnterCriticalSection(&resourceStoreCriticalSection); /* this is overkill really, but I suppose it should be thread safe */
51     wineD3DGlobalStatistics->glsurfaceram     += glram;
52     TRACE("Adjusted gl ram by %ld to %d\n", glram, wineD3DGlobalStatistics->glsurfaceram);
53     result = wineD3DGlobalStatistics->glsurfaceram;
54     LeaveCriticalSection(&resourceStoreCriticalSection);
55     return result;
56
57 }
58
59 IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion, IUnknown *parent) {
60     IWineD3DImpl* 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     /* TODO: Move this off to device and possibly x11drv */
67     /* Create a critical section for a dll global data store */
68     InitializeCriticalSectionAndSpinCount(&resourceStoreCriticalSection, 0x80000400);
69
70     /*Create a structure for storing global data in*/
71     if(wineD3DGlobalStatistics == NULL){
72         TRACE("Createing global statistics store\n");
73         wineD3DGlobalStatistics = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wineD3DGlobalStatistics));
74
75     }
76
77
78     TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
79
80     return (IWineD3D *)object;
81 }
82
83 inline static DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
84 {
85     if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
86     if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
87     return ERROR_FILE_NOT_FOUND;
88 }
89
90 /* At process attach */
91 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
92 {
93     TRACE("WineD3D DLLMain Reason=%ld\n", fdwReason);
94     if (fdwReason == DLL_PROCESS_ATTACH)
95     {
96        HMODULE mod;
97        char buffer[MAX_PATH+10];
98        DWORD size = sizeof(buffer);
99        HKEY hkey = 0;
100        HKEY appkey = 0;
101        DWORD len;
102
103        DisableThreadLibraryCalls(hInstDLL);
104
105        mod = GetModuleHandleA( "winex11.drv" );
106        if (mod)
107        {
108            wine_tsx11_lock_ptr   = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
109            wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
110        }
111        /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
112        if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
113
114        len = GetModuleFileNameA( 0, buffer, MAX_PATH );
115        if (len && len < MAX_PATH)
116        {
117             HKEY tmpkey;
118             /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
119             if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
120             {
121                 char *p, *appname = buffer;
122                 if ((p = strrchr( appname, '/' ))) appname = p + 1;
123                 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
124                 strcat( appname, "\\Direct3D" );
125                 TRACE("appname = [%s]\n", appname);
126                 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
127                 RegCloseKey( tmpkey );
128             }
129        }
130
131        if ( 0 != hkey || 0 != appkey )
132        {
133             if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
134             {
135                 if (!strcmp(buffer,"none"))
136                 {
137                     TRACE("Disable vertex shaders\n");
138                     wined3d_settings.vs_mode = VS_NONE;
139                 }
140                 else if (!strcmp(buffer,"emulation"))
141                 {
142                     TRACE("Force SW vertex shaders\n");
143                     wined3d_settings.vs_mode = VS_SW;
144                 }
145             }
146             if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
147             {
148                 if (!strcmp(buffer,"enabled"))
149                 {
150                     TRACE("Allow pixel shaders\n");
151                     wined3d_settings.ps_mode = PS_HW;
152                 }
153                 if (!strcmp(buffer,"disabled"))
154                 {
155                     TRACE("Disable pixel shaders\n");
156                     wined3d_settings.ps_mode = PS_NONE;
157                 }
158             }
159             if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
160             {
161                 if (!strcmp(buffer,"none"))
162                 {
163                     TRACE("Disable Vertex Buffer Hardware support\n");
164                     wined3d_settings.vbo_mode = VBO_NONE;
165                 }
166                 else if (!strcmp(buffer,"hardware"))
167                 {
168                     TRACE("Allow Vertex Buffer Hardware support\n");
169                     wined3d_settings.vbo_mode = VBO_HW;
170                 }
171             }
172             if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
173             {
174                 if (!strcmp(buffer,"enabled"))
175                 {
176                     TRACE("Use of GL Shading Language enabled for systems that support it\n");
177                     wined3d_settings.glslRequested = TRUE;
178                 }
179                 else
180                 {
181                     TRACE("Use of GL Shading Language disabled\n");
182                 }
183             }
184             if ( !get_config_key( hkey, appkey, "Nonpower2Mode", buffer, size) )
185             {
186                 if (!strcmp(buffer,"none"))
187                 {
188                     TRACE("Using default non-power2 textures\n");
189                     wined3d_settings.nonpower2_mode = NP2_NONE;
190
191                 }
192                 else if (!strcmp(buffer,"repack"))
193                 {
194                     TRACE("Repacking non-power2 textre\n");
195                     wined3d_settings.nonpower2_mode = NP2_REPACK;
196                 }
197                 /* There will be a couple of other choices for nonpow2, they are: TextureRecrangle and OpenGL 2 */
198             }
199        }
200        if (wined3d_settings.vs_mode == VS_HW)
201            TRACE("Allow HW vertex shaders\n");
202        if (wined3d_settings.ps_mode == PS_NONE)
203            TRACE("Disable pixel shaders\n");
204        if (wined3d_settings.vbo_mode == VBO_NONE)
205            TRACE("Disable Vertex Buffer Hardware support\n");
206        if (wined3d_settings.glslRequested)
207            TRACE("If supported by your system, GL Shading Language will be used\n");
208        if (wined3d_settings.nonpower2_mode == NP2_REPACK)
209            TRACE("Repacking non-power2 textures\n");
210
211        if (appkey) RegCloseKey( appkey );
212        if (hkey) RegCloseKey( hkey );
213     }
214     return TRUE;
215 }