wined3d: Do not fail if the adapter info can't be initialized.
[wine/multimedia.git] / dlls / wined3d / wined3d_main.c
blobd1cf28aa454a4de3f14df65747d20006b1182f07
1 /*
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
23 #include "config.h"
25 #include "initguid.h"
26 #include "wined3d_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(wine_d3d);
30 int num_lock = 0;
31 void (*wine_tsx11_lock_ptr)(void) = NULL;
32 void (*wine_tsx11_unlock_ptr)(void) = NULL;
35 /* When updating default value here, make sure to update winecfg as well,
36 * where appropriate. */
37 wined3d_settings_t wined3d_settings =
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 */
48 WineD3DGlobalStatistics *wineD3DGlobalStatistics = NULL;
50 long globalChangeGlRam(long glram){
51 /* FIXME: replace this function with object tracking */
52 int result;
54 wineD3DGlobalStatistics->glsurfaceram += glram;
55 TRACE("Adjusted gl ram by %ld to %d\n", glram, wineD3DGlobalStatistics->glsurfaceram);
56 result = wineD3DGlobalStatistics->glsurfaceram;
57 return result;
61 IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion, IUnknown *parent) {
62 IWineD3DImpl* object;
64 if (!InitAdapters()) {
65 WARN("Failed to initialize direct3d adapters, Direct3D will not be available\n");
66 if(dxVersion > 7) {
67 ERR("Direct3D%d is not available without opengl\n", dxVersion);
68 return NULL;
72 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
73 object->lpVtbl = &IWineD3D_Vtbl;
74 object->dxVersion = dxVersion;
75 object->ref = 1;
76 object->parent = parent;
78 /*Create a structure for storing global data in*/
79 if(wineD3DGlobalStatistics == NULL){
80 TRACE("Creating global statistics store\n");
81 wineD3DGlobalStatistics = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wineD3DGlobalStatistics));
85 TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
87 return (IWineD3D *)object;
90 static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
92 if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
93 if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
94 return ERROR_FILE_NOT_FOUND;
97 /* At process attach */
98 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
100 TRACE("WineD3D DLLMain Reason=%d\n", fdwReason);
101 if (fdwReason == DLL_PROCESS_ATTACH)
103 HMODULE mod;
104 char buffer[MAX_PATH+10];
105 DWORD size = sizeof(buffer);
106 HKEY hkey = 0;
107 HKEY appkey = 0;
108 DWORD len;
109 wined3d_settings.emulated_textureram = 64*1024*1024;
111 DisableThreadLibraryCalls(hInstDLL);
113 mod = GetModuleHandleA( "winex11.drv" );
114 if (mod)
116 wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
117 wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
119 /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
120 if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
122 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
123 if (len && len < MAX_PATH)
125 HKEY tmpkey;
126 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
127 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
129 char *p, *appname = buffer;
130 if ((p = strrchr( appname, '/' ))) appname = p + 1;
131 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
132 strcat( appname, "\\Direct3D" );
133 TRACE("appname = [%s]\n", appname);
134 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
135 RegCloseKey( tmpkey );
139 if ( 0 != hkey || 0 != appkey )
141 if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
143 if (!strcmp(buffer,"none"))
145 TRACE("Disable vertex shaders\n");
146 wined3d_settings.vs_mode = VS_NONE;
149 if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
151 if (!strcmp(buffer,"enabled"))
153 TRACE("Allow pixel shaders\n");
154 wined3d_settings.ps_mode = PS_HW;
156 if (!strcmp(buffer,"disabled"))
158 TRACE("Disable pixel shaders\n");
159 wined3d_settings.ps_mode = PS_NONE;
162 if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
164 if (!strcmp(buffer,"none"))
166 TRACE("Disable Vertex Buffer Hardware support\n");
167 wined3d_settings.vbo_mode = VBO_NONE;
169 else if (!strcmp(buffer,"hardware"))
171 TRACE("Allow Vertex Buffer Hardware support\n");
172 wined3d_settings.vbo_mode = VBO_HW;
175 if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
177 if (!strcmp(buffer,"enabled"))
179 TRACE("Use of GL Shading Language enabled for systems that support it\n");
180 wined3d_settings.glslRequested = TRUE;
182 else
184 TRACE("Use of GL Shading Language disabled\n");
187 if ( !get_config_key( hkey, appkey, "OffscreenRenderingMode", buffer, size) )
189 if (!strcmp(buffer,"backbuffer"))
191 TRACE("Using the backbuffer for offscreen rendering\n");
192 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
194 else if (!strcmp(buffer,"pbuffer"))
196 TRACE("Using PBuffers for offscreen rendering\n");
197 wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
199 else if (!strcmp(buffer,"fbo"))
201 TRACE("Using FBOs for offscreen rendering\n");
202 wined3d_settings.offscreen_rendering_mode = ORM_FBO;
205 if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
207 if (!strcmp(buffer,"disabled"))
209 TRACE("Disabling render target locking\n");
210 wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
212 else if (!strcmp(buffer,"readdraw"))
214 TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
215 wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
217 else if (!strcmp(buffer,"readtex"))
219 TRACE("Using glReadPixels for render target reading and textures for writing\n");
220 wined3d_settings.rendertargetlock_mode = RTL_READTEX;
222 else if (!strcmp(buffer,"texdraw"))
224 TRACE("Using textures for render target reading and glDrawPixels for writing\n");
225 wined3d_settings.rendertargetlock_mode = RTL_TEXDRAW;
227 else if (!strcmp(buffer,"textex"))
229 TRACE("Reading render targets via textures and writing via textures\n");
230 wined3d_settings.rendertargetlock_mode = RTL_TEXTEX;
233 if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
235 int TmpVideoMemorySize = atoi(buffer);
236 if(TmpVideoMemorySize > 0)
238 wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
239 TRACE("Use %iMB = %d byte for emulated_textureram\n",
240 TmpVideoMemorySize,
241 wined3d_settings.emulated_textureram);
243 else
244 ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
247 if (wined3d_settings.vs_mode == VS_HW)
248 TRACE("Allow HW vertex shaders\n");
249 if (wined3d_settings.ps_mode == PS_NONE)
250 TRACE("Disable pixel shaders\n");
251 if (wined3d_settings.vbo_mode == VBO_NONE)
252 TRACE("Disable Vertex Buffer Hardware support\n");
253 if (wined3d_settings.glslRequested)
254 TRACE("If supported by your system, GL Shading Language will be used\n");
256 if (appkey) RegCloseKey( appkey );
257 if (hkey) RegCloseKey( hkey );
259 return TRUE;