wined3d: Check real depth/stencil capabilities based on WGL pixel formats.
[wine/gsoc_dplay.git] / dlls / wined3d / wined3d_main.c
blob26e7f707cad06030084bf96754422c243617cdd9
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 TRUE, /* Use of GLSL enabled by default */
43 ORM_BACKBUFFER, /* Use the backbuffer to do offscreen rendering */
44 RTL_AUTO, /* Automatically determine best locking method */
45 0, /* The default of memory is set in FillGLCaps */
46 NULL /* No wine logo by default */
49 IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion, IUnknown *parent) {
50 IWineD3DImpl* object;
52 if (!InitAdapters()) {
53 WARN("Failed to initialize direct3d adapters, Direct3D will not be available\n");
54 if(dxVersion > 7) {
55 ERR("Direct3D%d is not available without opengl\n", dxVersion);
56 return NULL;
60 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;
66 TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
68 return (IWineD3D *)object;
71 static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
73 if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
74 if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
75 return ERROR_FILE_NOT_FOUND;
78 static void wined3d_do_nothing(void)
82 /* At process attach */
83 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
85 TRACE("WineD3D DLLMain Reason=%d\n", fdwReason);
86 if (fdwReason == DLL_PROCESS_ATTACH)
88 HMODULE mod;
89 char buffer[MAX_PATH+10];
90 DWORD size = sizeof(buffer);
91 HKEY hkey = 0;
92 HKEY appkey = 0;
93 DWORD len;
94 WNDCLASSA wc;
96 /* We need our own window class for a fake window which we use to retrieve GL capabilities */
97 /* We might need CS_OWNDC in the future if we notice strange things on Windows.
98 * Various articles/posts about OpenGL problems on Windows recommend this. */
99 wc.style = CS_HREDRAW | CS_VREDRAW;
100 wc.lpfnWndProc = DefWindowProcA;
101 wc.cbClsExtra = 0;
102 wc.cbWndExtra = 0;
103 wc.hInstance = hInstDLL;
104 wc.hIcon = LoadIconA(NULL, (LPCSTR)IDI_WINLOGO);
105 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
106 wc.hbrBackground = NULL;
107 wc.lpszMenuName = NULL;
108 wc.lpszClassName = "WineD3D_OpenGL";
110 if (!RegisterClassA(&wc) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
112 ERR("Failed to register window class 'WineD3D_OpenGL'!\n");
113 return FALSE;
116 DisableThreadLibraryCalls(hInstDLL);
118 mod = GetModuleHandleA( "winex11.drv" );
119 if (mod)
121 wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
122 wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
124 else /* We are most likely on Windows */
126 wine_tsx11_lock_ptr = wined3d_do_nothing;
127 wine_tsx11_unlock_ptr = wined3d_do_nothing;
129 /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
130 if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
132 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
133 if (len && len < MAX_PATH)
135 HKEY tmpkey;
136 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
137 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
139 char *p, *appname = buffer;
140 if ((p = strrchr( appname, '/' ))) appname = p + 1;
141 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
142 strcat( appname, "\\Direct3D" );
143 TRACE("appname = [%s]\n", appname);
144 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
145 RegCloseKey( tmpkey );
149 if ( 0 != hkey || 0 != appkey )
151 if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
153 if (!strcmp(buffer,"none"))
155 TRACE("Disable vertex shaders\n");
156 wined3d_settings.vs_mode = VS_NONE;
159 if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
161 if (!strcmp(buffer,"enabled"))
163 TRACE("Allow pixel shaders\n");
164 wined3d_settings.ps_mode = PS_HW;
166 if (!strcmp(buffer,"disabled"))
168 TRACE("Disable pixel shaders\n");
169 wined3d_settings.ps_mode = PS_NONE;
172 if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
174 if (!strcmp(buffer,"none"))
176 TRACE("Disable Vertex Buffer Hardware support\n");
177 wined3d_settings.vbo_mode = VBO_NONE;
179 else if (!strcmp(buffer,"hardware"))
181 TRACE("Allow Vertex Buffer Hardware support\n");
182 wined3d_settings.vbo_mode = VBO_HW;
185 if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
187 if (!strcmp(buffer,"disabled"))
189 TRACE("Use of GL Shading Language disabled\n");
190 wined3d_settings.glslRequested = FALSE;
193 if ( !get_config_key( hkey, appkey, "OffscreenRenderingMode", buffer, size) )
195 if (!strcmp(buffer,"backbuffer"))
197 TRACE("Using the backbuffer for offscreen rendering\n");
198 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
200 else if (!strcmp(buffer,"pbuffer"))
202 TRACE("Using PBuffers for offscreen rendering\n");
203 wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
205 else if (!strcmp(buffer,"fbo"))
207 TRACE("Using FBOs for offscreen rendering\n");
208 wined3d_settings.offscreen_rendering_mode = ORM_FBO;
211 if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
213 if (!strcmp(buffer,"disabled"))
215 TRACE("Disabling render target locking\n");
216 wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
218 else if (!strcmp(buffer,"readdraw"))
220 TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
221 wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
223 else if (!strcmp(buffer,"readtex"))
225 TRACE("Using glReadPixels for render target reading and textures for writing\n");
226 wined3d_settings.rendertargetlock_mode = RTL_READTEX;
228 else if (!strcmp(buffer,"texdraw"))
230 TRACE("Using textures for render target reading and glDrawPixels for writing\n");
231 wined3d_settings.rendertargetlock_mode = RTL_TEXDRAW;
233 else if (!strcmp(buffer,"textex"))
235 TRACE("Reading render targets via textures and writing via textures\n");
236 wined3d_settings.rendertargetlock_mode = RTL_TEXTEX;
239 if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
241 int TmpVideoMemorySize = atoi(buffer);
242 if(TmpVideoMemorySize > 0)
244 wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
245 TRACE("Use %iMB = %d byte for emulated_textureram\n",
246 TmpVideoMemorySize,
247 wined3d_settings.emulated_textureram);
249 else
250 ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
252 if ( !get_config_key( hkey, appkey, "WineLogo", buffer, size) )
254 wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, strlen(buffer) + 1);
255 if(wined3d_settings.logo) strcpy(wined3d_settings.logo, buffer);
258 if (wined3d_settings.vs_mode == VS_HW)
259 TRACE("Allow HW vertex shaders\n");
260 if (wined3d_settings.ps_mode == PS_NONE)
261 TRACE("Disable pixel shaders\n");
262 if (wined3d_settings.vbo_mode == VBO_NONE)
263 TRACE("Disable Vertex Buffer Hardware support\n");
264 if (wined3d_settings.glslRequested)
265 TRACE("If supported by your system, GL Shading Language will be used\n");
267 if (appkey) RegCloseKey( appkey );
268 if (hkey) RegCloseKey( hkey );
270 return TRUE;