2 * Direct3D wine internal interface main
4 * Copyright 2002-2003 The wine-d3d team
5 * Copyright 2002-2003 Raphael Junqueira
6 * Copyright 2004 Jason Edmeades
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.
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.
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
26 #include "wined3d_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(wine_d3d);
31 void (*wine_tsx11_lock_ptr)(void) = NULL;
32 void (*wine_tsx11_unlock_ptr)(void) = NULL;
35 wined3d_settings_t wined3d_settings =
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 */
43 WineD3DGlobalStatistics *wineD3DGlobalStatistics = NULL;
44 CRITICAL_SECTION resourceStoreCriticalSection;
46 long globalChangeGlRam(long glram){
47 /* FIXME: replace this function with object tracking */
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);
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;
64 object->parent = parent;
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);
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));
78 TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
80 return (IWineD3D *)object;
83 inline static DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
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;
90 /* At process attach */
91 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
93 TRACE("WineD3D DLLMain Reason=%ld\n", fdwReason);
94 if (fdwReason == DLL_PROCESS_ATTACH)
97 char buffer[MAX_PATH+10];
98 DWORD size = sizeof(buffer);
103 DisableThreadLibraryCalls(hInstDLL);
105 mod = GetModuleHandleA( "winex11.drv" );
108 wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
109 wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
111 /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
112 if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
114 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
115 if (len && len < MAX_PATH)
118 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
119 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
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 );
131 if ( 0 != hkey || 0 != appkey )
133 if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
135 if (!strcmp(buffer,"none"))
137 TRACE("Disable vertex shaders\n");
138 wined3d_settings.vs_mode = VS_NONE;
140 else if (!strcmp(buffer,"emulation"))
142 TRACE("Force SW vertex shaders\n");
143 wined3d_settings.vs_mode = VS_SW;
146 if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
148 if (!strcmp(buffer,"enabled"))
150 TRACE("Allow pixel shaders\n");
151 wined3d_settings.ps_mode = PS_HW;
153 if (!strcmp(buffer,"disabled"))
155 TRACE("Disable pixel shaders\n");
156 wined3d_settings.ps_mode = PS_NONE;
159 if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
161 if (!strcmp(buffer,"none"))
163 TRACE("Disable Vertex Buffer Hardware support\n");
164 wined3d_settings.vbo_mode = VBO_NONE;
166 else if (!strcmp(buffer,"hardware"))
168 TRACE("Allow Vertex Buffer Hardware support\n");
169 wined3d_settings.vbo_mode = VBO_HW;
172 if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
174 if (!strcmp(buffer,"enabled"))
176 TRACE("Use of GL Shading Language enabled for systems that support it\n");
177 wined3d_settings.glslRequested = TRUE;
181 TRACE("Use of GL Shading Language disabled\n");
184 if ( !get_config_key( hkey, appkey, "Nonpower2Mode", buffer, size) )
186 if (!strcmp(buffer,"none"))
188 TRACE("Using default non-power2 textures\n");
189 wined3d_settings.nonpower2_mode = NP2_NONE;
192 else if (!strcmp(buffer,"repack"))
194 TRACE("Repacking non-power2 textre\n");
195 wined3d_settings.nonpower2_mode = NP2_REPACK;
197 /* There will be a couple of other choices for nonpow2, they are: TextureRecrangle and OpenGL 2 */
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");
211 if (appkey) RegCloseKey( appkey );
212 if (hkey) RegCloseKey( hkey );