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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 */
42 WineD3DGlobalStatistics *wineD3DGlobalStatistics = NULL;
43 CRITICAL_SECTION resourceStoreCriticalSection;
45 long globalChangeGlRam(long glram){
46 /* FIXME: replace this function with object tracking */
49 EnterCriticalSection(&resourceStoreCriticalSection); /* this is overkill really, but I suppose it should be thread safe */
50 wineD3DGlobalStatistics->glsurfaceram += glram;
51 TRACE("Adjusted gl ram by %ld to %d\n", glram, wineD3DGlobalStatistics->glsurfaceram);
52 result = wineD3DGlobalStatistics->glsurfaceram;
53 LeaveCriticalSection(&resourceStoreCriticalSection);
58 IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion, IUnknown *parent) {
59 IWineD3DImpl* object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
60 object->lpVtbl = &IWineD3D_Vtbl;
61 object->dxVersion = dxVersion;
63 object->parent = parent;
65 /* TODO: Move this off to device and possibly x11drv */
66 /* Create a critical section for a dll global data store */
67 InitializeCriticalSectionAndSpinCount(&resourceStoreCriticalSection, 0x80000400);
69 /*Create a structure for storing global data in*/
70 if(wineD3DGlobalStatistics == NULL){
71 TRACE("Createing global statistics store\n");
72 wineD3DGlobalStatistics = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wineD3DGlobalStatistics));
77 TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
79 return (IWineD3D *)object;
82 inline static DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
84 if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
85 if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
86 return ERROR_FILE_NOT_FOUND;
89 /* At process attach */
90 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
92 TRACE("WineD3D DLLMain Reason=%ld\n", fdwReason);
93 if (fdwReason == DLL_PROCESS_ATTACH)
96 char buffer[MAX_PATH+10];
97 DWORD size = sizeof(buffer);
102 DisableThreadLibraryCalls(hInstDLL);
104 mod = GetModuleHandleA( "winex11.drv" );
107 wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
108 wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
110 /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
111 if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
113 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
114 if (len && len < MAX_PATH)
117 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
118 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
120 char *p, *appname = buffer;
121 if ((p = strrchr( appname, '/' ))) appname = p + 1;
122 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
123 strcat( appname, "\\Direct3D" );
124 TRACE("appname = [%s]\n", appname);
125 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
126 RegCloseKey( tmpkey );
130 if ( 0 != hkey || 0 != appkey )
132 if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
134 if (!strcmp(buffer,"none"))
136 TRACE("Disable vertex shaders\n");
137 wined3d_settings.vs_mode = VS_NONE;
139 else if (!strcmp(buffer,"emulation"))
141 TRACE("Force SW vertex shaders\n");
142 wined3d_settings.vs_mode = VS_SW;
145 if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
147 if (!strcmp(buffer,"enabled"))
149 TRACE("Allow pixel shaders\n");
150 wined3d_settings.ps_mode = PS_HW;
152 if (!strcmp(buffer,"disabled"))
154 TRACE("Disable pixel shaders\n");
155 wined3d_settings.ps_mode = PS_NONE;
158 if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
160 if (!strcmp(buffer,"none"))
162 TRACE("Disable Vertex Buffer Hardware support\n");
163 wined3d_settings.vbo_mode = VBO_NONE;
165 else if (!strcmp(buffer,"hardware"))
167 TRACE("Allow Vertex Buffer Hardware support\n");
168 wined3d_settings.vbo_mode = VBO_HW;
171 if ( !get_config_key( hkey, appkey, "Nonpower2Mode", buffer, size) )
173 if (!strcmp(buffer,"none"))
175 TRACE("Using default non-power2 textures\n");
176 wined3d_settings.nonpower2_mode = NP2_NONE;
179 else if (!strcmp(buffer,"repack"))
181 TRACE("Repacking non-power2 textre\n");
182 wined3d_settings.nonpower2_mode = NP2_REPACK;
184 /* There will be a couple of other choices for nonpow2, they are: TextureRecrangle and OpenGL 2 */
187 if (wined3d_settings.vs_mode == VS_HW)
188 TRACE("Allow HW vertex shaders\n");
189 if (wined3d_settings.ps_mode == PS_NONE)
190 TRACE("Disable pixel shaders\n");
191 if (wined3d_settings.vbo_mode == VBO_NONE)
192 TRACE("Disable Vertex Buffer Hardware support\n");
193 if (wined3d_settings.nonpower2_mode == NP2_REPACK)
194 TRACE("Repacking non-power2 textures\n");
196 if (appkey) RegCloseKey( appkey );
197 if (hkey) RegCloseKey( hkey );