1 /****************************************************************************
3 * Mesa 3-D graphics library
4 * Direct3D Driver Interface
6 * ========================================================================
8 * Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
25 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * ======================================================================
31 * Environment: Windows 9x (Win32)
33 * Description: Win32 DllMain functions.
35 ****************************************************************************/
37 // INITGUID must only be defined once.
38 // Don't put it in a shared header file!
39 // GLD3 uses dxguid.lib, so INITGUID must *not* be used!
42 #endif // _USE_GLD3_WGL
46 //#include "snap/graphics.h"
47 //#include "drvlib/os/os.h"
50 typedef void (APIENTRY
*LPDGLSPLASHSCREEN
)(int, int, char*);
51 #include "gld_driver.h"
54 // ***********************************************************************
56 BOOL bInitialized
= FALSE
; // callback driver initialized?
57 BOOL bExited
= FALSE
; // callback driver exited this instance?
58 HINSTANCE hInstanceDll
= NULL
; // DLL instance handle
60 static BOOL bDriverValidated
= FALSE
; // prior validation status
61 static BOOL bSplashScreen
= TRUE
; // Splash Screen ?
62 static BOOL bValidINIFound
= FALSE
; // Have we found a valid INI file?
64 HHOOK hKeyHook
= NULL
; // global keyboard handler hook
66 // Multi-threaded support needs to be reflected in Mesa code. (DaveM)
67 int _gld_bMultiThreaded
= FALSE
;
69 // ***********************************************************************
71 DWORD dwLogging
= 0; // Logging flag
72 DWORD dwDebugLevel
= 0; // Log debug level
74 char szLogPath
[_MAX_PATH
] = {"\0"}; // Log file path
75 char szSNAPPath
[_MAX_PATH
] = {"\0"}; // SNAP driver path
78 DGL_wglFuncs wglFuncs
= {
80 DGL_ChoosePixelFormat
,
83 DGL_CreateLayerContext
,
85 DGL_DescribeLayerPlane
,
86 DGL_DescribePixelFormat
,
87 DGL_GetCurrentContext
,
89 DGL_GetDefaultProcAddress
,
90 DGL_GetLayerPaletteEntries
,
94 DGL_RealizeLayerPalette
,
95 DGL_SetLayerPaletteEntries
,
102 DGL_UseFontOutlinesA
,
103 DGL_UseFontOutlinesW
,
106 DGL_mesaFuncs mesaFuncs
= {
107 sizeof(DGL_mesaFuncs
),
109 #endif // _USE_GLD3_WGL
111 // ***********************************************************************
114 DWORD dwDriver
; // 0=SciTech SW, 1=Direct3D SW, 2=Direct3D HW
115 BOOL bMipmapping
; // 0=off, 1=on
116 BOOL bMultitexture
; // 0=off, 1=on
117 BOOL bWaitForRetrace
; // 0=off, 1=on
118 BOOL bFullscreenBlit
; // 0=off, 1=on
119 BOOL bFastFPU
; // 0=off, 1=on
120 BOOL bDirectDrawPersistant
;// 0=off, 1=on
121 BOOL bPersistantBuffers
; // 0=off, 1=on
122 DWORD dwLogging
; // 0=off, 1=normal, 2=crash-proof
123 DWORD dwLoggingSeverity
; // 0=all, 1=warnings+errors, 2=errors only
124 BOOL bMessageBoxWarnings
;// 0=off, 1=on
125 BOOL bMultiThreaded
; // 0=off, 1=on
126 BOOL bAppCustomizations
; // 0=off, 1=on
127 BOOL bHotKeySupport
; // 0=off, 1=on
128 BOOL bSplashScreen
; // 0=off, 1=on
132 // New for GLDirect 3.0
134 DWORD dwAdapter
; // DX8 adpater ordinal
135 DWORD dwTnL
; // Transform & Lighting type
136 DWORD dwMultisample
; // DX8 multisample type
137 #endif // _USE_GLD3_WGL
140 static INI_settings ini
;
142 // ***********************************************************************
144 BOOL APIENTRY
DGL_initDriver(
149 DGL_wglFuncs
*lpWglFuncs
,
150 DGL_mesaFuncs
*lpMesaFuncs
)
152 // Check for valid pointers
153 if ((lpWglFuncs
== NULL
) || (lpMesaFuncs
== NULL
))
156 // Check for valid structs
157 if (lpWglFuncs
->dwSize
!= sizeof(DGL_wglFuncs
)) {
161 // Check for valid structs
162 if (lpMesaFuncs
->dwSize
!= sizeof(DGL_mesaFuncs
)) {
166 // Copy the Mesa functions
167 memcpy(&mesaFuncs
, lpMesaFuncs
, sizeof(DGL_mesaFuncs
));
169 // Pass back the wgl functions
170 memcpy(lpWglFuncs
, &wglFuncs
, sizeof(DGL_wglFuncs
));
171 #endif // _USE_GLD3_WGL
173 // Finally initialize the callback driver
174 if (!dglInitDriver())
180 // ***********************************************************************
185 char szModuleFilename
[MAX_PATH
];
186 char szSystemDirectory
[MAX_PATH
];
187 const char szSectionName
[] = "Config";
188 char szINIFile
[MAX_PATH
];
191 // Now using the DLL module handle. KeithH, 24/May/2000.
192 // Addendum: GetModuleFileName(NULL, ... returns process filename,
193 // GetModuleFileName(hModule, ... returns DLL filename,
195 // Get the dll path and filename.
196 GetModuleFileName(hInstance
, &szModuleFilename
[0], MAX_PATH
); // NULL for current process
197 // Get the System directory.
198 GetSystemDirectory(&szSystemDirectory
[0], MAX_PATH
);
200 // Test to see if DLL is in system directory.
201 if (strnicmp(szModuleFilename
, szSystemDirectory
, strlen(szSystemDirectory
))==0) {
202 // DLL *is* in system directory.
203 // Return FALSE to indicate that registry keys should be read.
207 // Compose filename of INI file
208 strcpy(szINIFile
, szModuleFilename
);
209 pos
= strlen(szINIFile
);
210 while (szINIFile
[pos
] != '\\') {
213 szINIFile
[pos
+1] = '\0';
214 // Use run-time DLL path for log file too
215 strcpy(szLogPath
, szINIFile
);
216 szLogPath
[pos
] = '\0';
217 // Complete full INI file path
218 strcat(szINIFile
, "gldirect.ini");
220 // Read settings from private INI file.
221 // Note that defaults are contained in the calls.
222 ini
.dwDriver
= GetPrivateProfileInt(szSectionName
, "dwDriver", 2, szINIFile
);
223 ini
.bMipmapping
= GetPrivateProfileInt(szSectionName
, "bMipmapping", 1, szINIFile
);
224 ini
.bMultitexture
= GetPrivateProfileInt(szSectionName
, "bMultitexture", 1, szINIFile
);
225 ini
.bWaitForRetrace
= GetPrivateProfileInt(szSectionName
, "bWaitForRetrace", 0, szINIFile
);
226 ini
.bFullscreenBlit
= GetPrivateProfileInt(szSectionName
, "bFullscreenBlit", 0, szINIFile
);
227 ini
.bFastFPU
= GetPrivateProfileInt(szSectionName
, "bFastFPU", 1, szINIFile
);
228 ini
.bDirectDrawPersistant
= GetPrivateProfileInt(szSectionName
, "bPersistantDisplay", 0, szINIFile
);
229 ini
.bPersistantBuffers
= GetPrivateProfileInt(szSectionName
, "bPersistantResources", 0, szINIFile
);
230 ini
.dwLogging
= GetPrivateProfileInt(szSectionName
, "dwLogging", 0, szINIFile
);
231 ini
.dwLoggingSeverity
= GetPrivateProfileInt(szSectionName
, "dwLoggingSeverity", 0, szINIFile
);
232 ini
.bMessageBoxWarnings
= GetPrivateProfileInt(szSectionName
, "bMessageBoxWarnings", 0, szINIFile
);
233 ini
.bMultiThreaded
= GetPrivateProfileInt(szSectionName
, "bMultiThreaded", 0, szINIFile
);
234 ini
.bAppCustomizations
= GetPrivateProfileInt(szSectionName
, "bAppCustomizations", 1, szINIFile
);
235 ini
.bHotKeySupport
= GetPrivateProfileInt(szSectionName
, "bHotKeySupport", 0, szINIFile
);
236 ini
.bSplashScreen
= GetPrivateProfileInt(szSectionName
, "bSplashScreen", 1, szINIFile
);
239 // New for GLDirect 3.x
240 ini
.dwAdapter
= GetPrivateProfileInt(szSectionName
, "dwAdapter", 0, szINIFile
);
241 // dwTnL now defaults to zero (chooses TnL at runtime). KeithH
242 ini
.dwTnL
= GetPrivateProfileInt(szSectionName
, "dwTnL", 0, szINIFile
);
243 ini
.dwMultisample
= GetPrivateProfileInt(szSectionName
, "dwMultisample", 0, szINIFile
);
249 // ***********************************************************************
251 BOOL
dllReadRegistry(
254 // Read settings from INI file, if available
255 bValidINIFound
= FALSE
;
256 if (ReadINIFile(hInstance
)) {
257 const char *szRendering
[3] = {
258 "SciTech Software Renderer",
259 "Direct3D MMX Software Renderer",
260 "Direct3D Hardware Renderer"
264 glb
.bHardware
= (ini
.dwDriver
== 2) ? 1 : 0;
265 #ifndef _USE_GLD3_WGL
266 memset(&glb
.ddGuid
, 0, sizeof(glb
.ddGuid
));
267 glb
.d3dGuid
= (ini
.dwDriver
== 2) ? IID_IDirect3DHALDevice
: IID_IDirect3DRGBDevice
;
268 #endif // _USE_GLD3_WGL
269 strcpy(glb
.szDDName
, "Primary");
270 strcpy(glb
.szD3DName
, szRendering
[ini
.dwDriver
]);
271 glb
.dwRendering
= ini
.dwDriver
;
272 glb
.bUseMipmaps
= ini
.bMipmapping
;
273 glb
.bMultitexture
= ini
.bMultitexture
;
274 glb
.bWaitForRetrace
= ini
.bWaitForRetrace
;
275 glb
.bFullscreenBlit
= ini
.bFullscreenBlit
;
276 glb
.bFastFPU
= ini
.bFastFPU
;
277 glb
.bDirectDrawPersistant
= ini
.bDirectDrawPersistant
;
278 glb
.bPersistantBuffers
= ini
.bPersistantBuffers
;
279 dwLogging
= ini
.dwLogging
;
280 dwDebugLevel
= ini
.dwLoggingSeverity
;
281 glb
.bMessageBoxWarnings
= ini
.bMessageBoxWarnings
;
282 glb
.bMultiThreaded
= ini
.bMultiThreaded
;
283 glb
.bAppCustomizations
= ini
.bAppCustomizations
;
284 glb
.bHotKeySupport
= ini
.bHotKeySupport
;
285 bSplashScreen
= ini
.bSplashScreen
;
287 // New for GLDirect 3.x
288 glb
.dwAdapter
= ini
.dwAdapter
;
289 glb
.dwDriver
= ini
.dwDriver
;
290 glb
.dwTnL
= ini
.dwTnL
;
291 glb
.dwMultisample
= ini
.dwMultisample
;
293 bValidINIFound
= TRUE
;
296 // Read settings from registry
300 DWORD dwType
= REG_SZ
; // Registry data type for strings
304 #define REG_READ_DWORD(a, b) \
305 cbValSize = sizeof(b); \
306 if (ERROR_SUCCESS != RegQueryValueEx( hReg, (a), \
307 NULL, NULL, (LPBYTE)&(b), &cbValSize )) \
308 bRegistryError = TRUE;
310 #define REG_READ_DEVICEID(a, b) \
311 cbValSize = MAX_DDDEVICEID_STRING; \
312 if(ERROR_SUCCESS != RegQueryValueEx(hReg, (a), 0, &dwType, \
313 (LPBYTE)&(b), &cbValSize)) \
314 bRegistryError = TRUE;
316 #define REG_READ_STRING(a, b) \
317 cbValSize = sizeof((b)); \
318 if(ERROR_SUCCESS != RegQueryValueEx(hReg, (a), 0, &dwType, \
319 (LPBYTE)&(b), &cbValSize)) \
320 bRegistryError = TRUE;
322 // Read settings from the registry.
324 // Open the registry key for the current user if it exists.
325 bSuccess
= (ERROR_SUCCESS
== RegOpenKeyEx(HKEY_CURRENT_USER
,
326 DIRECTGL_REG_SETTINGS_KEY
,
330 // Otherwise open the registry key for the local machine.
332 bSuccess
= (ERROR_SUCCESS
== RegOpenKeyEx(DIRECTGL_REG_KEY_ROOT
,
333 DIRECTGL_REG_SETTINGS_KEY
,
340 bRegistryError
= FALSE
;
342 REG_READ_DWORD(DIRECTGL_REG_SETTING_PRIMARY
, glb
.bPrimary
);
343 REG_READ_DWORD(DIRECTGL_REG_SETTING_D3D_HW
, glb
.bHardware
);
344 #ifndef _USE_GLD3_WGL
345 REG_READ_DWORD(DIRECTGL_REG_SETTING_DD_GUID
, glb
.ddGuid
);
346 REG_READ_DWORD(DIRECTGL_REG_SETTING_D3D_GUID
, glb
.d3dGuid
);
347 #endif // _USE_GLD3_WGL
348 REG_READ_DWORD(DIRECTGL_REG_SETTING_LOGGING
, dwLogging
);
349 REG_READ_DWORD(DIRECTGL_REG_SETTING_DEBUGLEVEL
, dwDebugLevel
);
350 REG_READ_DWORD(DIRECTGL_REG_SETTING_RENDERING
, glb
.dwRendering
);
351 REG_READ_DWORD(DIRECTGL_REG_SETTING_MULTITEXTURE
, glb
.bMultitexture
);
352 REG_READ_DWORD(DIRECTGL_REG_SETTING_WAITFORRETRACE
, glb
.bWaitForRetrace
);
353 REG_READ_DWORD(DIRECTGL_REG_SETTING_FULLSCREENBLIT
, glb
.bFullscreenBlit
);
354 REG_READ_DWORD(DIRECTGL_REG_SETTING_USEMIPMAPS
, glb
.bUseMipmaps
);
356 REG_READ_DEVICEID(DIRECTGL_REG_SETTING_DD_NAME
, glb
.szDDName
);
357 REG_READ_DEVICEID(DIRECTGL_REG_SETTING_D3D_NAME
, glb
.szD3DName
);
359 REG_READ_DWORD(DIRECTGL_REG_SETTING_MSGBOXWARNINGS
, glb
.bMessageBoxWarnings
);
360 REG_READ_DWORD(DIRECTGL_REG_SETTING_PERSISTDISPLAY
, glb
.bDirectDrawPersistant
);
361 REG_READ_DWORD(DIRECTGL_REG_SETTING_PERSISTBUFFERS
, glb
.bPersistantBuffers
);
362 REG_READ_DWORD(DIRECTGL_REG_SETTING_FASTFPU
, glb
.bFastFPU
);
363 REG_READ_DWORD(DIRECTGL_REG_SETTING_HOTKEYS
, glb
.bHotKeySupport
);
364 REG_READ_DWORD(DIRECTGL_REG_SETTING_MULTITHREAD
, glb
.bMultiThreaded
);
365 REG_READ_DWORD(DIRECTGL_REG_SETTING_APPCUSTOM
, glb
.bAppCustomizations
);
366 REG_READ_DWORD(DIRECTGL_REG_SETTING_SPLASHSCREEN
, bSplashScreen
);
369 // New for GLDirect 3.x
370 glb
.dwDriver
= glb
.dwRendering
;
371 REG_READ_DWORD(DIRECTGL_REG_SETTING_ADAPTER
, glb
.dwAdapter
);
372 REG_READ_DWORD(DIRECTGL_REG_SETTING_TNL
, glb
.dwTnL
);
373 REG_READ_DWORD(DIRECTGL_REG_SETTING_MULTISAMPLE
, glb
.dwMultisample
);
378 // Open the global registry key for GLDirect
379 bSuccess
= (ERROR_SUCCESS
== RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
380 DIRECTGL_REG_SETTINGS_KEY
,
385 // Read the installation path for GLDirect
386 REG_READ_STRING("InstallLocation",szLogPath
);
390 if (bRegistryError
|| !bSuccess
)
396 #undef REG_READ_DWORD
397 #undef REG_READ_DEVICEID
398 #undef REG_READ_STRING
402 // ***********************************************************************
404 BOOL
dllWriteRegistry(
408 DWORD dwCreateDisposition
, cbValSize
;
409 BOOL bRegistryError
= FALSE
;
411 #define REG_WRITE_DWORD(a, b) \
412 cbValSize = sizeof(b); \
413 if (ERROR_SUCCESS != RegSetValueEx( hReg, (a), \
414 0, REG_DWORD, (LPBYTE)&(b), cbValSize )) \
415 bRegistryError = TRUE;
417 if (ERROR_SUCCESS
== RegCreateKeyEx( DIRECTGL_REG_KEY_ROOT
, DIRECTGL_REG_SETTINGS_KEY
,
418 0, NULL
, 0, KEY_WRITE
, NULL
, &hReg
,
419 &dwCreateDisposition
)) {
420 RegFlushKey(hReg
); // Make sure keys are written to disk
430 #undef REG_WRITE_DWORD
433 // ***********************************************************************
435 void dglInitHotKeys(HINSTANCE hInstance
)
437 // Hot-Key support at all?
438 if (!glb
.bHotKeySupport
)
441 // Install global keyboard interceptor
442 hKeyHook
= SetWindowsHookEx(WH_KEYBOARD
, dglKeyProc
, hInstance
, 0);
445 // ***********************************************************************
447 void dglExitHotKeys(void)
449 // Hot-Key support at all?
450 if (!glb
.bHotKeySupport
)
453 // Remove global keyboard interceptor
455 UnhookWindowsHookEx(hKeyHook
);
459 // ***********************************************************************
461 // Note: This app-customization step must be performed in both the main
462 // OpenGL32 driver and the callback driver DLLs for multithreading option.
463 void dglSetAppCustomizations(void)
465 char szModuleFileName
[MAX_PATH
];
466 int iSize
= MAX_PATH
;
468 // Get the currently loaded EXE filename.
469 GetModuleFileName(NULL
, &szModuleFileName
[0], MAX_PATH
); // NULL for current process
470 strupr(szModuleFileName
);
471 iSize
= strlen(szModuleFileName
);
473 // Check for specific EXEs and adjust global settings accordingly
475 // NOTE: In GLD3.x "bDirectDrawPersistant" corresponds to IDirect3D8 and
476 // "bPersistantBuffers" corresponds to IDirect3DDevice8. KeithH
478 // Case 1: 3DStudio must be multi-threaded
479 // Added: Discreet GMAX (3DStudio MAX 4 for gamers. KeithH)
480 if (strstr(szModuleFileName
, "3DSMAX.EXE")
481 || strstr(szModuleFileName
, "3DSVIZ.EXE")
482 || strstr(szModuleFileName
, "GMAX.EXE")) {
483 glb
.bMultiThreaded
= TRUE
;
484 glb
.bDirectDrawPersistant
= FALSE
;
485 glb
.bPersistantBuffers
= FALSE
;
489 // Case 2: Solid Edge must use pre-allocated resources for all GLRCs
490 if (strstr(szModuleFileName
, "PART.EXE")
491 || strstr(szModuleFileName
, "ASSEMBL.EXE")
492 || strstr(szModuleFileName
, "DRAFT.EXE")
493 || strstr(szModuleFileName
, "SMARTVW.EXE")
494 || strstr(szModuleFileName
, "SMETAL.EXE")) {
495 glb
.bMultiThreaded
= FALSE
;
496 glb
.bDirectDrawPersistant
= TRUE
;
497 glb
.bPersistantBuffers
= FALSE
;
501 // Case 3: Sudden Depth creates and destroys GLRCs on paint commands
502 if (strstr(szModuleFileName
, "SUDDEPTH.EXE")
503 || strstr(szModuleFileName
, "SUDDEMO.EXE")) {
504 glb
.bMultiThreaded
= FALSE
;
505 glb
.bDirectDrawPersistant
= TRUE
;
506 glb
.bPersistantBuffers
= TRUE
;
507 glb
.bFullscreenBlit
= TRUE
;
511 // Case 4: StereoGraphics test apps create and destroy GLRCs on paint commands
512 if (strstr(szModuleFileName
, "REDBLUE.EXE")
513 || strstr(szModuleFileName
, "DIAGNOSE.EXE")) {
514 glb
.bMultiThreaded
= FALSE
;
515 glb
.bDirectDrawPersistant
= TRUE
;
516 glb
.bPersistantBuffers
= TRUE
;
520 // Case 5: Pipes screen savers share multiple GLRCs for same window
521 if (strstr(szModuleFileName
, "PIPES.SCR")
522 || (strstr(szModuleFileName
, "PIPES") && strstr(szModuleFileName
, ".SCR"))) {
523 glb
.bMultiThreaded
= FALSE
;
524 glb
.bDirectDrawPersistant
= TRUE
;
525 glb
.bPersistantBuffers
= TRUE
;
529 // Case 6: AutoVue uses sub-viewport ops which are temporarily broken in stereo window
530 if (strstr(szModuleFileName
, "AVWIN.EXE")) {
531 glb
.bMultiThreaded
= FALSE
;
532 glb
.bDirectDrawPersistant
= TRUE
;
533 glb
.bPersistantBuffers
= TRUE
;
536 // Case 7: Quake3 is waiting for DDraw objects to be released at exit
537 if (strstr(szModuleFileName
, "QUAKE")) {
538 glb
.bMultiThreaded
= FALSE
;
539 glb
.bDirectDrawPersistant
= FALSE
;
540 glb
.bPersistantBuffers
= FALSE
;
541 glb
.bFullscreenBlit
= FALSE
;
544 // Case 8: Reflection GLX server is unable to switch contexts at run-time
545 if (strstr(szModuleFileName
, "RX.EXE")) {
546 glb
.bMultiThreaded
= FALSE
;
547 glb
.bMessageBoxWarnings
= FALSE
;
550 // Case 9: Original AutoCAD 2000 must share DDraw objects across GLRCs
551 if (strstr(szModuleFileName
, "ACAD.EXE")) {
552 glb
.bFastFPU
= FALSE
;
553 if (GetModuleHandle("wopengl6.hdi") != NULL
) {
554 glb
.bMultiThreaded
= FALSE
;
555 glb
.bDirectDrawPersistant
= TRUE
;
556 glb
.bPersistantBuffers
= FALSE
;
562 // ***********************************************************************
564 BOOL
dglInitDriver(void)
566 UCHAR szExeName
[MAX_PATH
];
567 const char *szRendering
[] = {
572 static BOOL bWarnOnce
= FALSE
;
574 // Already initialized?
578 // Moved from DllMain DLL_PROCESS_ATTACH:
580 // (Re-)Init defaults
583 // Read registry or INI file settings
584 if (!dllReadRegistry(hInstanceDll
)) {
586 MessageBox( NULL
, "GLDirect has not been configured.\n\n"
587 "Please run the configuration program\n"
588 "before using GLDirect with applications.\n",
589 "GLDirect", MB_OK
| MB_ICONWARNING
);
595 // Must do this as early as possible.
596 // Need to read regkeys/ini-file first though.
597 gldInitDriverPointers(glb
.dwDriver
);
599 // Create private driver globals
600 _gldDriver
.CreatePrivateGlobals();
602 // Overide settings with application customizations
603 if (glb
.bAppCustomizations
)
604 dglSetAppCustomizations();
606 //#ifndef _USE_GLD3_WGL
607 // Set the global memory type to either sysmem or vidmem
608 glb
.dwMemoryType
= glb
.bHardware
? DDSCAPS_VIDEOMEMORY
: DDSCAPS_SYSTEMMEMORY
;
611 // Multi-threaded support overides persistant display support
612 if (glb
.bMultiThreaded
)
613 glb
.bDirectDrawPersistant
= glb
.bPersistantBuffers
= FALSE
;
615 // Multi-threaded support needs to be reflected in Mesa code. (DaveM)
616 _gld_bMultiThreaded
= glb
.bMultiThreaded
;
619 ddlogPathOption(szLogPath
);
620 ddlogWarnOption(glb
.bMessageBoxWarnings
);
621 ddlogOpen((DDLOG_loggingMethodType
)dwLogging
,
622 (DDLOG_severityType
)dwDebugLevel
);
624 // Obtain the name of the calling app
625 ddlogMessage(DDLOG_SYSTEM
, "Driver : SciTech GLDirect 4.0\n");
626 GetModuleFileName(NULL
, szExeName
, sizeof(szExeName
));
627 ddlogPrintf(DDLOG_SYSTEM
, "Executable : %s", szExeName
);
629 ddlogPrintf(DDLOG_SYSTEM
, "DirectDraw device: %s", glb
.szDDName
);
630 ddlogPrintf(DDLOG_SYSTEM
, "Direct3D driver : %s", glb
.szD3DName
);
632 ddlogPrintf(DDLOG_SYSTEM
, "Rendering type : %s", szRendering
[glb
.dwRendering
]);
634 ddlogPrintf(DDLOG_SYSTEM
, "Multithreaded : %s", glb
.bMultiThreaded
? "Enabled" : "Disabled");
635 ddlogPrintf(DDLOG_SYSTEM
, "Display resources: %s", glb
.bDirectDrawPersistant
? "Persistant" : "Instanced");
636 ddlogPrintf(DDLOG_SYSTEM
, "Buffer resources : %s", glb
.bPersistantBuffers
? "Persistant" : "Instanced");
638 dglInitContextState();
639 dglBuildPixelFormatList();
640 //dglBuildTextureFormatList();
642 // D3D callback driver is now successfully initialized
644 // D3D callback driver is now ready to be exited
650 // ***********************************************************************
652 void dglExitDriver(void)
655 // Only need to clean up once per instance:
656 // May be called implicitly from DLL_PROCESS_DETACH,
657 // or explicitly from DGL_exitDriver().
662 // DDraw objects may be invalid when DLL unloads.
665 // Clean-up sequence (moved from DLL_PROCESS_DETACH)
666 #ifndef _USE_GLD3_WGL
667 dglReleaseTextureFormatList();
669 dglReleasePixelFormatList();
670 dglDeleteContextState();
673 _gldDriver
.DestroyPrivateGlobals();
677 __except(EXCEPTION_EXECUTE_HANDLER
) {
678 ddlogPrintf(DDLOG_WARN
, "Exception raised in dglExitDriver.");
681 // Close the log file
685 // ***********************************************************************
693 case DLL_PROCESS_ATTACH
:
694 // Cache DLL instance handle
695 hInstanceDll
= hInstance
;
697 // Flag that callback driver has yet to be initialized
698 bInitialized
= bExited
= FALSE
;
700 #ifndef _USE_GLD3_WGL
701 // Init internal Mesa function pointers
702 memset(&mesaFuncs
, 0, sizeof(DGL_mesaFuncs
));
703 #endif // _USE_GLD3_WGL
708 // Defer rest of DLL initialization to 1st WGL function call
711 case DLL_PROCESS_DETACH
:
712 // Call exit clean-up sequence
720 // ***********************************************************************
722 void APIENTRY
DGL_exitDriver(void)
724 // Call exit clean-up sequence
728 // ***********************************************************************
730 void APIENTRY
DGL_reinitDriver(void)
732 // Force init sequence again
733 bInitialized
= bExited
= FALSE
;
737 // ***********************************************************************
739 int WINAPI
DllInitialize(
744 // Some Watcom compiled executables require this.
745 return DllMain(hInstance
, fdwReason
, pvReserved
);
748 // ***********************************************************************
750 void DGL_LoadSplashScreen(int piReg
, char* pszUser
)
752 HINSTANCE hSplashDll
= NULL
;
753 LPDGLSPLASHSCREEN dglSplashScreen
= NULL
;
754 static BOOL bOnce
= FALSE
;
756 static char szUser
[255] = {"\0"};
758 // Display splash screen at all?
762 // Only display splash screen once
767 // Make local copy of string for passing to DLL
769 strcpy(szUser
, pszUser
);
772 // Load Splash Screen DLL
773 // (If it fails to load for any reason, we don't care...)
774 hSplashDll
= LoadLibrary("gldsplash.dll");
776 // Execute the Splash Screen function
777 dglSplashScreen
= (LPDGLSPLASHSCREEN
)GetProcAddress(hSplashDll
, "GLDSplashScreen");
779 (*dglSplashScreen
)(1, iReg
, szUser
);
780 // Don't unload the DLL since splash screen dialog is modeless now
784 // ***********************************************************************
788 char *szCaption
= "SciTech GLDirect Driver";
789 UINT uType
= MB_OK
| MB_ICONEXCLAMATION
;
792 // (Re)build pixelformat list
793 if (glb
.bPixelformatsDirty
)
794 _gldDriver
.BuildPixelformatList();
797 // Check to see if we have already validated
798 if (bDriverValidated
&& bInitialized
)
801 // Since all (most) the WGL functions must be validated at this point,
802 // this also insure that the callback driver is completely initialized.
804 if (!dglInitDriver()) {
806 "The GLDirect driver could not initialize.\n\n"
807 "Please run the configuration program to\n"
808 "properly configure the driver, or else\n"
809 "re-run the installation program.", szCaption
, uType
);
816 // ***********************************************************************