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
7 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(wine_d3d);
32 void (*wine_tsx11_lock_ptr)(void) = NULL;
33 void (*wine_tsx11_unlock_ptr)(void) = NULL;
36 /* When updating default value here, make sure to update winecfg as well,
37 * where appropriate. */
38 wined3d_settings_t wined3d_settings =
40 VS_HW, /* Hardware by default */
41 PS_HW, /* Hardware by default */
42 VBO_HW, /* Hardware by default */
43 TRUE, /* Use of GLSL enabled by default */
44 ORM_BACKBUFFER, /* Use the backbuffer to do offscreen rendering */
45 RTL_AUTO, /* Automatically determine best locking method */
46 0, /* The default of memory is set in FillGLCaps */
47 NULL /* No wine logo by default */
50 IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion, IUnknown *parent) {
53 if (!InitAdapters()) {
54 WARN("Failed to initialize direct3d adapters, Direct3D will not be available\n");
56 ERR("Direct3D%d is not available without opengl\n", dxVersion);
61 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
62 object->lpVtbl = &IWineD3D_Vtbl;
63 object->dxVersion = dxVersion;
65 object->parent = parent;
67 TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
69 return (IWineD3D *)object;
72 static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
74 if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
75 if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
76 return ERROR_FILE_NOT_FOUND;
79 static void wined3d_do_nothing(void)
83 /* At process attach */
84 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
86 TRACE("WineD3D DLLMain Reason=%d\n", fdwReason);
87 if (fdwReason == DLL_PROCESS_ATTACH)
90 char buffer[MAX_PATH+10];
91 DWORD size = sizeof(buffer);
97 atifs_shader_backend.shader_dll_load_init();
98 glsl_shader_backend.shader_dll_load_init();
99 arb_program_shader_backend.shader_dll_load_init();
100 none_shader_backend.shader_dll_load_init();
102 /* We need our own window class for a fake window which we use to retrieve GL capabilities */
103 /* We might need CS_OWNDC in the future if we notice strange things on Windows.
104 * Various articles/posts about OpenGL problems on Windows recommend this. */
105 wc.style = CS_HREDRAW | CS_VREDRAW;
106 wc.lpfnWndProc = DefWindowProcA;
109 wc.hInstance = hInstDLL;
110 wc.hIcon = LoadIconA(NULL, (LPCSTR)IDI_WINLOGO);
111 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
112 wc.hbrBackground = NULL;
113 wc.lpszMenuName = NULL;
114 wc.lpszClassName = "WineD3D_OpenGL";
116 if (!RegisterClassA(&wc) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
118 ERR("Failed to register window class 'WineD3D_OpenGL'!\n");
122 DisableThreadLibraryCalls(hInstDLL);
124 mod = GetModuleHandleA( "winex11.drv" );
127 wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
128 wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
130 else /* We are most likely on Windows */
132 wine_tsx11_lock_ptr = wined3d_do_nothing;
133 wine_tsx11_unlock_ptr = wined3d_do_nothing;
135 /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
136 if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
138 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
139 if (len && len < MAX_PATH)
142 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
143 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
145 char *p, *appname = buffer;
146 if ((p = strrchr( appname, '/' ))) appname = p + 1;
147 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
148 strcat( appname, "\\Direct3D" );
149 TRACE("appname = [%s]\n", appname);
150 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
151 RegCloseKey( tmpkey );
155 if ( 0 != hkey || 0 != appkey )
157 if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
159 if (!strcmp(buffer,"none"))
161 TRACE("Disable vertex shaders\n");
162 wined3d_settings.vs_mode = VS_NONE;
165 if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
167 if (!strcmp(buffer,"enabled"))
169 TRACE("Allow pixel shaders\n");
170 wined3d_settings.ps_mode = PS_HW;
172 if (!strcmp(buffer,"disabled"))
174 TRACE("Disable pixel shaders\n");
175 wined3d_settings.ps_mode = PS_NONE;
178 if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
180 if (!strcmp(buffer,"none"))
182 TRACE("Disable Vertex Buffer Hardware support\n");
183 wined3d_settings.vbo_mode = VBO_NONE;
185 else if (!strcmp(buffer,"hardware"))
187 TRACE("Allow Vertex Buffer Hardware support\n");
188 wined3d_settings.vbo_mode = VBO_HW;
191 if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
193 if (!strcmp(buffer,"disabled"))
195 TRACE("Use of GL Shading Language disabled\n");
196 wined3d_settings.glslRequested = FALSE;
199 if ( !get_config_key( hkey, appkey, "OffscreenRenderingMode", buffer, size) )
201 if (!strcmp(buffer,"backbuffer"))
203 TRACE("Using the backbuffer for offscreen rendering\n");
204 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
206 else if (!strcmp(buffer,"pbuffer"))
208 TRACE("Using PBuffers for offscreen rendering\n");
209 wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
211 else if (!strcmp(buffer,"fbo"))
213 TRACE("Using FBOs for offscreen rendering\n");
214 wined3d_settings.offscreen_rendering_mode = ORM_FBO;
217 if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
219 if (!strcmp(buffer,"disabled"))
221 TRACE("Disabling render target locking\n");
222 wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
224 else if (!strcmp(buffer,"readdraw"))
226 TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
227 wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
229 else if (!strcmp(buffer,"readtex"))
231 TRACE("Using glReadPixels for render target reading and textures for writing\n");
232 wined3d_settings.rendertargetlock_mode = RTL_READTEX;
234 else if (!strcmp(buffer,"texdraw"))
236 TRACE("Using textures for render target reading and glDrawPixels for writing\n");
237 wined3d_settings.rendertargetlock_mode = RTL_TEXDRAW;
239 else if (!strcmp(buffer,"textex"))
241 TRACE("Reading render targets via textures and writing via textures\n");
242 wined3d_settings.rendertargetlock_mode = RTL_TEXTEX;
245 if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
247 int TmpVideoMemorySize = atoi(buffer);
248 if(TmpVideoMemorySize > 0)
250 wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
251 TRACE("Use %iMB = %d byte for emulated_textureram\n",
253 wined3d_settings.emulated_textureram);
256 ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
258 if ( !get_config_key( hkey, appkey, "WineLogo", buffer, size) )
260 wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, strlen(buffer) + 1);
261 if(wined3d_settings.logo) strcpy(wined3d_settings.logo, buffer);
264 if (wined3d_settings.vs_mode == VS_HW)
265 TRACE("Allow HW vertex shaders\n");
266 if (wined3d_settings.ps_mode == PS_NONE)
267 TRACE("Disable pixel shaders\n");
268 if (wined3d_settings.vbo_mode == VBO_NONE)
269 TRACE("Disable Vertex Buffer Hardware support\n");
270 if (wined3d_settings.glslRequested)
271 TRACE("If supported by your system, GL Shading Language will be used\n");
273 if (appkey) RegCloseKey( appkey );
274 if (hkey) RegCloseKey( hkey );