ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dll_main.c
Go to the documentation of this file.
00001 /****************************************************************************
00002 *
00003 *                        Mesa 3-D graphics library
00004 *                        Direct3D Driver Interface
00005 *
00006 *  ========================================================================
00007 *
00008 *   Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
00009 *
00010 *   Permission is hereby granted, free of charge, to any person obtaining a
00011 *   copy of this software and associated documentation files (the "Software"),
00012 *   to deal in the Software without restriction, including without limitation
00013 *   the rights to use, copy, modify, merge, publish, distribute, sublicense,
00014 *   and/or sell copies of the Software, and to permit persons to whom the
00015 *   Software is furnished to do so, subject to the following conditions:
00016 *
00017 *   The above copyright notice and this permission notice shall be included
00018 *   in all copies or substantial portions of the Software.
00019 *
00020 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00021 *   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00022 *   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00023 *   SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00024 *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00025 *   OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00026 *   SOFTWARE.
00027 *
00028 *  ======================================================================
00029 *
00030 * Language:     ANSI C
00031 * Environment:  Windows 9x (Win32)
00032 *
00033 * Description:  Win32 DllMain functions.
00034 *
00035 ****************************************************************************/
00036 
00037 // INITGUID must only be defined once.
00038 // Don't put it in a shared header file!
00039 // GLD3 uses dxguid.lib, so INITGUID must *not* be used!
00040 #ifndef _USE_GLD3_WGL
00041 #define INITGUID
00042 #endif // _USE_GLD3_WGL
00043 
00044 #include "dllmain.h"
00045 
00046 //#include "snap/graphics.h"
00047 //#include "drvlib/os/os.h"
00048 
00049 #ifdef _USE_GLD3_WGL
00050 typedef void (APIENTRY *LPDGLSPLASHSCREEN)(int, int, char*);
00051 #include "gld_driver.h"
00052 #endif
00053 
00054 // ***********************************************************************
00055 
00056 BOOL bInitialized = FALSE;              // callback driver initialized?
00057 BOOL bExited = FALSE;                   // callback driver exited this instance?
00058 HINSTANCE hInstanceDll = NULL;          // DLL instance handle
00059 
00060 static BOOL bDriverValidated = FALSE;   // prior validation status
00061 static BOOL bSplashScreen = TRUE;       // Splash Screen ?
00062 static BOOL bValidINIFound = FALSE;     // Have we found a valid INI file?
00063 
00064 HHOOK   hKeyHook = NULL;                // global keyboard handler hook
00065 
00066 // Multi-threaded support needs to be reflected in Mesa code. (DaveM)
00067 int _gld_bMultiThreaded = FALSE;
00068 
00069 // ***********************************************************************
00070 
00071 DWORD dwLogging = 0;                    // Logging flag
00072 DWORD dwDebugLevel = 0;                 // Log debug level
00073 
00074 char szLogPath[_MAX_PATH] = {"\0"};     // Log file path
00075 char szSNAPPath[_MAX_PATH] = {"\0"};    // SNAP driver path
00076 
00077 #ifndef _USE_GLD3_WGL
00078 DGL_wglFuncs wglFuncs = {
00079     sizeof(DGL_wglFuncs),
00080     DGL_ChoosePixelFormat,
00081     DGL_CopyContext,
00082     DGL_CreateContext,
00083     DGL_CreateLayerContext,
00084     DGL_DeleteContext,
00085     DGL_DescribeLayerPlane,
00086     DGL_DescribePixelFormat,
00087     DGL_GetCurrentContext,
00088     DGL_GetCurrentDC,
00089     DGL_GetDefaultProcAddress,
00090     DGL_GetLayerPaletteEntries,
00091     DGL_GetPixelFormat,
00092     DGL_GetProcAddress,
00093     DGL_MakeCurrent,
00094     DGL_RealizeLayerPalette,
00095     DGL_SetLayerPaletteEntries,
00096     DGL_SetPixelFormat,
00097     DGL_ShareLists,
00098     DGL_SwapBuffers,
00099     DGL_SwapLayerBuffers,
00100     DGL_UseFontBitmapsA,
00101     DGL_UseFontBitmapsW,
00102     DGL_UseFontOutlinesA,
00103     DGL_UseFontOutlinesW,
00104 };
00105 
00106 DGL_mesaFuncs mesaFuncs = {
00107     sizeof(DGL_mesaFuncs),
00108 };
00109 #endif // _USE_GLD3_WGL
00110 
00111 // ***********************************************************************
00112 
00113 typedef struct {
00114     DWORD   dwDriver;           // 0=SciTech SW, 1=Direct3D SW, 2=Direct3D HW
00115     BOOL    bMipmapping;        // 0=off, 1=on
00116     BOOL    bMultitexture;      // 0=off, 1=on
00117     BOOL    bWaitForRetrace;    // 0=off, 1=on
00118     BOOL    bFullscreenBlit;    // 0=off, 1=on
00119     BOOL    bFastFPU;           // 0=off, 1=on
00120     BOOL    bDirectDrawPersistant;// 0=off, 1=on
00121     BOOL    bPersistantBuffers; // 0=off, 1=on
00122     DWORD   dwLogging;          // 0=off, 1=normal, 2=crash-proof
00123     DWORD   dwLoggingSeverity;  // 0=all, 1=warnings+errors, 2=errors only
00124     BOOL    bMessageBoxWarnings;// 0=off, 1=on
00125     BOOL    bMultiThreaded;     // 0=off, 1=on
00126     BOOL    bAppCustomizations; // 0=off, 1=on
00127     BOOL    bHotKeySupport;     // 0=off, 1=on
00128     BOOL    bSplashScreen;      // 0=off, 1=on
00129 
00130 #ifdef _USE_GLD3_WGL
00131     //
00132     // New for GLDirect 3.0
00133     //
00134     DWORD   dwAdapter;          // DX8 adpater ordinal
00135     DWORD   dwTnL;              // Transform & Lighting type
00136     DWORD   dwMultisample;      // DX8 multisample type
00137 #endif // _USE_GLD3_WGL
00138 } INI_settings;
00139 
00140 static INI_settings ini;
00141 
00142 // ***********************************************************************
00143 
00144 BOOL APIENTRY DGL_initDriver(
00145 #ifdef _USE_GLD3_WGL
00146     void)
00147 {
00148 #else
00149     DGL_wglFuncs *lpWglFuncs,
00150     DGL_mesaFuncs *lpMesaFuncs)
00151 {
00152     // Check for valid pointers
00153     if ((lpWglFuncs == NULL) || (lpMesaFuncs == NULL))
00154         return FALSE;
00155 
00156     // Check for valid structs
00157     if (lpWglFuncs->dwSize != sizeof(DGL_wglFuncs)) {
00158         return FALSE;
00159     }
00160 
00161     // Check for valid structs
00162     if (lpMesaFuncs->dwSize != sizeof(DGL_mesaFuncs)) {
00163         return FALSE;
00164     }
00165 
00166     // Copy the Mesa functions
00167     memcpy(&mesaFuncs, lpMesaFuncs, sizeof(DGL_mesaFuncs));
00168 
00169     // Pass back the wgl functions
00170     memcpy(lpWglFuncs, &wglFuncs, sizeof(DGL_wglFuncs));
00171 #endif // _USE_GLD3_WGL
00172 
00173     // Finally initialize the callback driver
00174     if (!dglInitDriver())
00175         return FALSE;
00176 
00177     return TRUE;
00178 };
00179 
00180 // ***********************************************************************
00181 
00182 BOOL ReadINIFile(
00183     HINSTANCE hInstance)
00184 {
00185     char        szModuleFilename[MAX_PATH];
00186     char        szSystemDirectory[MAX_PATH];
00187     const char  szSectionName[] = "Config";
00188     char        szINIFile[MAX_PATH];
00189     int         pos;
00190 
00191     // Now using the DLL module handle. KeithH, 24/May/2000.
00192     // Addendum: GetModuleFileName(NULL, ...    returns process filename,
00193     //           GetModuleFileName(hModule, ... returns DLL filename,
00194 
00195     // Get the dll path and filename.
00196     GetModuleFileName(hInstance, &szModuleFilename[0], MAX_PATH); // NULL for current process
00197     // Get the System directory.
00198     GetSystemDirectory(&szSystemDirectory[0], MAX_PATH);
00199 
00200     // Test to see if DLL is in system directory.
00201     if (strnicmp(szModuleFilename, szSystemDirectory, strlen(szSystemDirectory))==0) {
00202         // DLL *is* in system directory.
00203         // Return FALSE to indicate that registry keys should be read.
00204         return FALSE;
00205     }
00206 
00207     // Compose filename of INI file
00208     strcpy(szINIFile, szModuleFilename);
00209     pos = strlen(szINIFile);
00210     while (szINIFile[pos] != '\\') {
00211         pos--;
00212     }
00213     szINIFile[pos+1] = '\0';
00214     // Use run-time DLL path for log file too
00215     strcpy(szLogPath, szINIFile);
00216     szLogPath[pos] = '\0';
00217     // Complete full INI file path
00218     strcat(szINIFile, "gldirect.ini");
00219 
00220     // Read settings from private INI file.
00221     // Note that defaults are contained in the calls.
00222     ini.dwDriver = GetPrivateProfileInt(szSectionName, "dwDriver", 2, szINIFile);
00223     ini.bMipmapping = GetPrivateProfileInt(szSectionName, "bMipmapping", 1, szINIFile);
00224     ini.bMultitexture = GetPrivateProfileInt(szSectionName, "bMultitexture", 1, szINIFile);
00225     ini.bWaitForRetrace = GetPrivateProfileInt(szSectionName, "bWaitForRetrace", 0, szINIFile);
00226     ini.bFullscreenBlit = GetPrivateProfileInt(szSectionName, "bFullscreenBlit", 0, szINIFile);
00227     ini.bFastFPU = GetPrivateProfileInt(szSectionName, "bFastFPU", 1, szINIFile);
00228     ini.bDirectDrawPersistant = GetPrivateProfileInt(szSectionName, "bPersistantDisplay", 0, szINIFile);
00229     ini.bPersistantBuffers = GetPrivateProfileInt(szSectionName, "bPersistantResources", 0, szINIFile);
00230     ini.dwLogging = GetPrivateProfileInt(szSectionName, "dwLogging", 0, szINIFile);
00231     ini.dwLoggingSeverity = GetPrivateProfileInt(szSectionName, "dwLoggingSeverity", 0, szINIFile);
00232     ini.bMessageBoxWarnings = GetPrivateProfileInt(szSectionName, "bMessageBoxWarnings", 0, szINIFile);
00233     ini.bMultiThreaded = GetPrivateProfileInt(szSectionName, "bMultiThreaded", 0, szINIFile);
00234     ini.bAppCustomizations = GetPrivateProfileInt(szSectionName, "bAppCustomizations", 1, szINIFile);
00235     ini.bHotKeySupport = GetPrivateProfileInt(szSectionName, "bHotKeySupport", 0, szINIFile);
00236     ini.bSplashScreen = GetPrivateProfileInt(szSectionName, "bSplashScreen", 1, szINIFile);
00237 
00238 #ifdef _USE_GLD3_WGL
00239     // New for GLDirect 3.x
00240     ini.dwAdapter       = GetPrivateProfileInt(szSectionName, "dwAdapter", 0, szINIFile);
00241     // dwTnL now defaults to zero (chooses TnL at runtime). KeithH
00242     ini.dwTnL           = GetPrivateProfileInt(szSectionName, "dwTnL", 0, szINIFile);
00243     ini.dwMultisample   = GetPrivateProfileInt(szSectionName, "dwMultisample", 0, szINIFile);
00244 #endif
00245 
00246     return TRUE;
00247 }
00248 
00249 // ***********************************************************************
00250 
00251 BOOL dllReadRegistry(
00252     HINSTANCE hInstance)
00253 {
00254     // Read settings from INI file, if available
00255     bValidINIFound = FALSE;
00256     if (ReadINIFile(hInstance)) {
00257         const char *szRendering[3] = {
00258             "SciTech Software Renderer",
00259             "Direct3D MMX Software Renderer",
00260             "Direct3D Hardware Renderer"
00261         };
00262         // Set globals
00263         glb.bPrimary = 1;
00264         glb.bHardware = (ini.dwDriver == 2) ? 1 : 0;
00265 #ifndef _USE_GLD3_WGL
00266         memset(&glb.ddGuid, 0, sizeof(glb.ddGuid));
00267         glb.d3dGuid = (ini.dwDriver == 2) ? IID_IDirect3DHALDevice : IID_IDirect3DRGBDevice;
00268 #endif // _USE_GLD3_WGL
00269         strcpy(glb.szDDName, "Primary");
00270         strcpy(glb.szD3DName, szRendering[ini.dwDriver]);
00271         glb.dwRendering = ini.dwDriver;
00272         glb.bUseMipmaps = ini.bMipmapping;
00273         glb.bMultitexture = ini.bMultitexture;
00274         glb.bWaitForRetrace = ini.bWaitForRetrace;
00275         glb.bFullscreenBlit = ini.bFullscreenBlit;
00276         glb.bFastFPU = ini.bFastFPU;
00277         glb.bDirectDrawPersistant = ini.bDirectDrawPersistant;
00278         glb.bPersistantBuffers = ini.bPersistantBuffers;
00279         dwLogging = ini.dwLogging;
00280         dwDebugLevel = ini.dwLoggingSeverity;
00281         glb.bMessageBoxWarnings = ini.bMessageBoxWarnings;
00282         glb.bMultiThreaded = ini.bMultiThreaded;
00283         glb.bAppCustomizations = ini.bAppCustomizations;
00284         glb.bHotKeySupport = ini.bHotKeySupport;
00285         bSplashScreen = ini.bSplashScreen;
00286 #ifdef _USE_GLD3_WGL
00287         // New for GLDirect 3.x
00288         glb.dwAdapter       = ini.dwAdapter;
00289         glb.dwDriver        = ini.dwDriver;
00290         glb.dwTnL           = ini.dwTnL;
00291         glb.dwMultisample   = ini.dwMultisample;
00292 #endif
00293         bValidINIFound = TRUE;
00294         return TRUE;
00295     }
00296     // Read settings from registry
00297     else {
00298     HKEY    hReg;
00299     DWORD   cbValSize;
00300     DWORD   dwType = REG_SZ; // Registry data type for strings
00301     BOOL    bRegistryError;
00302     BOOL    bSuccess;
00303 
00304 #define REG_READ_DWORD(a, b)                            \
00305     cbValSize = sizeof(b);                              \
00306     if (ERROR_SUCCESS != RegQueryValueEx( hReg, (a),    \
00307         NULL, NULL, (LPBYTE)&(b), &cbValSize ))         \
00308         bRegistryError = TRUE;
00309 
00310 #define REG_READ_DEVICEID(a, b)                                 \
00311     cbValSize = MAX_DDDEVICEID_STRING;                          \
00312     if(ERROR_SUCCESS != RegQueryValueEx(hReg, (a), 0, &dwType,  \
00313                     (LPBYTE)&(b), &cbValSize))                  \
00314         bRegistryError = TRUE;
00315 
00316 #define REG_READ_STRING(a, b)                                   \
00317     cbValSize = sizeof((b));                                    \
00318     if(ERROR_SUCCESS != RegQueryValueEx(hReg, (a), 0, &dwType,  \
00319                     (LPBYTE)&(b), &cbValSize))                  \
00320         bRegistryError = TRUE;
00321 
00322     // Read settings from the registry.
00323 
00324     // Open the registry key for the current user if it exists.
00325     bSuccess = (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER,
00326                                       DIRECTGL_REG_SETTINGS_KEY,
00327                                       0,
00328                                       KEY_READ,
00329                                       &hReg));
00330     // Otherwise open the registry key for the local machine.
00331     if (!bSuccess)
00332         bSuccess = (ERROR_SUCCESS == RegOpenKeyEx(DIRECTGL_REG_KEY_ROOT,
00333                                       DIRECTGL_REG_SETTINGS_KEY,
00334                                       0,
00335                                       KEY_READ,
00336                                       &hReg));
00337     if (!bSuccess)
00338         return FALSE;
00339 
00340     bRegistryError = FALSE;
00341 
00342     REG_READ_DWORD(DIRECTGL_REG_SETTING_PRIMARY, glb.bPrimary);
00343     REG_READ_DWORD(DIRECTGL_REG_SETTING_D3D_HW, glb.bHardware);
00344 #ifndef _USE_GLD3_WGL
00345     REG_READ_DWORD(DIRECTGL_REG_SETTING_DD_GUID, glb.ddGuid);
00346     REG_READ_DWORD(DIRECTGL_REG_SETTING_D3D_GUID, glb.d3dGuid);
00347 #endif // _USE_GLD3_WGL
00348     REG_READ_DWORD(DIRECTGL_REG_SETTING_LOGGING, dwLogging);
00349     REG_READ_DWORD(DIRECTGL_REG_SETTING_DEBUGLEVEL, dwDebugLevel);
00350     REG_READ_DWORD(DIRECTGL_REG_SETTING_RENDERING, glb.dwRendering);
00351     REG_READ_DWORD(DIRECTGL_REG_SETTING_MULTITEXTURE, glb.bMultitexture);
00352     REG_READ_DWORD(DIRECTGL_REG_SETTING_WAITFORRETRACE, glb.bWaitForRetrace);
00353     REG_READ_DWORD(DIRECTGL_REG_SETTING_FULLSCREENBLIT, glb.bFullscreenBlit);
00354     REG_READ_DWORD(DIRECTGL_REG_SETTING_USEMIPMAPS, glb.bUseMipmaps);
00355 
00356     REG_READ_DEVICEID(DIRECTGL_REG_SETTING_DD_NAME, glb.szDDName);
00357     REG_READ_DEVICEID(DIRECTGL_REG_SETTING_D3D_NAME, glb.szD3DName);
00358 
00359     REG_READ_DWORD(DIRECTGL_REG_SETTING_MSGBOXWARNINGS, glb.bMessageBoxWarnings);
00360     REG_READ_DWORD(DIRECTGL_REG_SETTING_PERSISTDISPLAY, glb.bDirectDrawPersistant);
00361     REG_READ_DWORD(DIRECTGL_REG_SETTING_PERSISTBUFFERS, glb.bPersistantBuffers);
00362     REG_READ_DWORD(DIRECTGL_REG_SETTING_FASTFPU, glb.bFastFPU);
00363     REG_READ_DWORD(DIRECTGL_REG_SETTING_HOTKEYS, glb.bHotKeySupport);
00364     REG_READ_DWORD(DIRECTGL_REG_SETTING_MULTITHREAD, glb.bMultiThreaded);
00365     REG_READ_DWORD(DIRECTGL_REG_SETTING_APPCUSTOM, glb.bAppCustomizations);
00366     REG_READ_DWORD(DIRECTGL_REG_SETTING_SPLASHSCREEN, bSplashScreen);
00367 
00368 #ifdef _USE_GLD3_WGL
00369     // New for GLDirect 3.x
00370     glb.dwDriver = glb.dwRendering;
00371     REG_READ_DWORD(DIRECTGL_REG_SETTING_ADAPTER, glb.dwAdapter);
00372     REG_READ_DWORD(DIRECTGL_REG_SETTING_TNL, glb.dwTnL);
00373     REG_READ_DWORD(DIRECTGL_REG_SETTING_MULTISAMPLE, glb.dwMultisample);
00374 #endif
00375 
00376     RegCloseKey(hReg);
00377 
00378     // Open the global registry key for GLDirect
00379     bSuccess = (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
00380                                       DIRECTGL_REG_SETTINGS_KEY,
00381                                       0,
00382                                       KEY_READ,
00383                                       &hReg));
00384     if (bSuccess) {
00385         // Read the installation path for GLDirect
00386         REG_READ_STRING("InstallLocation",szLogPath);
00387         RegCloseKey(hReg);
00388         }
00389 
00390     if (bRegistryError || !bSuccess)
00391         return FALSE;
00392     else
00393         
00394         return TRUE;
00395 
00396 #undef REG_READ_DWORD
00397 #undef REG_READ_DEVICEID
00398 #undef REG_READ_STRING
00399     }
00400 }
00401 
00402 // ***********************************************************************
00403 
00404 BOOL dllWriteRegistry(
00405     void )
00406 {
00407     HKEY    hReg;
00408     DWORD   dwCreateDisposition, cbValSize;
00409     BOOL    bRegistryError = FALSE;
00410 
00411 #define REG_WRITE_DWORD(a, b)                           \
00412     cbValSize = sizeof(b);                              \
00413     if (ERROR_SUCCESS != RegSetValueEx( hReg, (a),      \
00414         0, REG_DWORD, (LPBYTE)&(b), cbValSize ))        \
00415         bRegistryError = TRUE;
00416 
00417     if (ERROR_SUCCESS == RegCreateKeyEx( DIRECTGL_REG_KEY_ROOT, DIRECTGL_REG_SETTINGS_KEY,
00418                                         0, NULL, 0, KEY_WRITE, NULL, &hReg,
00419                                         &dwCreateDisposition )) {
00420         RegFlushKey(hReg); // Make sure keys are written to disk
00421         RegCloseKey(hReg);
00422         hReg = NULL;
00423         }
00424 
00425     if (bRegistryError)
00426         return FALSE;
00427     else
00428         return TRUE;
00429 
00430 #undef REG_WRITE_DWORD
00431 }
00432 
00433 // ***********************************************************************
00434 
00435 void dglInitHotKeys(HINSTANCE hInstance)
00436 {
00437     // Hot-Key support at all?
00438     if (!glb.bHotKeySupport)
00439         return;
00440 
00441     // Install global keyboard interceptor
00442     hKeyHook = SetWindowsHookEx(WH_KEYBOARD, dglKeyProc, hInstance, 0);
00443 }
00444 
00445 // ***********************************************************************
00446 
00447 void dglExitHotKeys(void)
00448 {
00449     // Hot-Key support at all?
00450     if (!glb.bHotKeySupport)
00451         return;
00452 
00453     // Remove global keyboard interceptor
00454     if (hKeyHook)
00455         UnhookWindowsHookEx(hKeyHook);
00456     hKeyHook = NULL;
00457 }
00458 
00459 // ***********************************************************************
00460 
00461 // Note: This app-customization step must be performed in both the main
00462 // OpenGL32 driver and the callback driver DLLs for multithreading option.
00463 void dglSetAppCustomizations(void)
00464 {
00465     char        szModuleFileName[MAX_PATH];
00466     int         iSize = MAX_PATH;
00467 
00468     // Get the currently loaded EXE filename.
00469     GetModuleFileName(NULL, &szModuleFileName[0], MAX_PATH); // NULL for current process
00470     strupr(szModuleFileName);
00471     iSize = strlen(szModuleFileName);
00472 
00473     // Check for specific EXEs and adjust global settings accordingly
00474 
00475     // NOTE: In GLD3.x "bDirectDrawPersistant" corresponds to IDirect3D8 and
00476     //       "bPersistantBuffers" corresponds to IDirect3DDevice8. KeithH
00477 
00478     // Case 1: 3DStudio must be multi-threaded
00479     // Added: Discreet GMAX (3DStudio MAX 4 for gamers. KeithH)
00480     if (strstr(szModuleFileName, "3DSMAX.EXE")
00481         || strstr(szModuleFileName, "3DSVIZ.EXE")
00482         || strstr(szModuleFileName, "GMAX.EXE")) {
00483         glb.bMultiThreaded = TRUE;
00484         glb.bDirectDrawPersistant = FALSE;
00485         glb.bPersistantBuffers = FALSE;
00486         return;
00487     }
00488 
00489     // Case 2: Solid Edge must use pre-allocated resources for all GLRCs
00490     if (strstr(szModuleFileName, "PART.EXE")
00491         || strstr(szModuleFileName, "ASSEMBL.EXE")
00492         || strstr(szModuleFileName, "DRAFT.EXE")
00493         || strstr(szModuleFileName, "SMARTVW.EXE")
00494         || strstr(szModuleFileName, "SMETAL.EXE")) {
00495         glb.bMultiThreaded = FALSE;
00496         glb.bDirectDrawPersistant = TRUE;
00497         glb.bPersistantBuffers = FALSE;
00498         return;
00499     }
00500 
00501     // Case 3: Sudden Depth creates and destroys GLRCs on paint commands
00502     if (strstr(szModuleFileName, "SUDDEPTH.EXE")
00503         || strstr(szModuleFileName, "SUDDEMO.EXE")) {
00504         glb.bMultiThreaded = FALSE;
00505         glb.bDirectDrawPersistant = TRUE;
00506         glb.bPersistantBuffers = TRUE;
00507         glb.bFullscreenBlit = TRUE;
00508         return;
00509     }
00510 
00511     // Case 4: StereoGraphics test apps create and destroy GLRCs on paint commands
00512     if (strstr(szModuleFileName, "REDBLUE.EXE")
00513         || strstr(szModuleFileName, "DIAGNOSE.EXE")) {
00514         glb.bMultiThreaded = FALSE;
00515         glb.bDirectDrawPersistant = TRUE;
00516         glb.bPersistantBuffers = TRUE;
00517         return;
00518     }
00519 
00520     // Case 5: Pipes screen savers share multiple GLRCs for same window
00521     if (strstr(szModuleFileName, "PIPES.SCR")
00522         || (strstr(szModuleFileName, "PIPES") && strstr(szModuleFileName, ".SCR"))) {
00523         glb.bMultiThreaded = FALSE;
00524         glb.bDirectDrawPersistant = TRUE;
00525         glb.bPersistantBuffers = TRUE;
00526         return;
00527     }
00528 
00529     // Case 6: AutoVue uses sub-viewport ops which are temporarily broken in stereo window
00530     if (strstr(szModuleFileName, "AVWIN.EXE")) {
00531         glb.bMultiThreaded = FALSE;
00532         glb.bDirectDrawPersistant = TRUE;
00533         glb.bPersistantBuffers = TRUE;
00534         return;
00535     }
00536     // Case 7: Quake3 is waiting for DDraw objects to be released at exit
00537     if (strstr(szModuleFileName, "QUAKE")) {
00538         glb.bMultiThreaded = FALSE;
00539         glb.bDirectDrawPersistant = FALSE;
00540         glb.bPersistantBuffers = FALSE;
00541         glb.bFullscreenBlit = FALSE;
00542         return;
00543     }
00544     // Case 8: Reflection GLX server is unable to switch contexts at run-time
00545     if (strstr(szModuleFileName, "RX.EXE")) {
00546         glb.bMultiThreaded = FALSE;
00547         glb.bMessageBoxWarnings = FALSE;
00548         return;
00549     }
00550     // Case 9: Original AutoCAD 2000 must share DDraw objects across GLRCs
00551     if (strstr(szModuleFileName, "ACAD.EXE")) {
00552         glb.bFastFPU = FALSE;
00553         if (GetModuleHandle("wopengl6.hdi") != NULL) {
00554         glb.bMultiThreaded = FALSE;
00555         glb.bDirectDrawPersistant = TRUE;
00556         glb.bPersistantBuffers = FALSE;
00557         }
00558         return;
00559     }
00560 }
00561 
00562 // ***********************************************************************
00563 
00564 BOOL dglInitDriver(void)
00565 {
00566     UCHAR szExeName[MAX_PATH];
00567     const char *szRendering[] = {
00568         "Mesa Software",
00569         "Direct3D RGB SW",
00570         "Direct3D HW",
00571     };
00572     static BOOL bWarnOnce = FALSE;
00573 
00574     // Already initialized?
00575     if (bInitialized)
00576         return TRUE;
00577 
00578     // Moved from DllMain DLL_PROCESS_ATTACH:
00579 
00580         // (Re-)Init defaults
00581         dglInitGlobals();
00582 
00583         // Read registry or INI file settings
00584         if (!dllReadRegistry(hInstanceDll)) {
00585             if (!bWarnOnce)
00586                 MessageBox( NULL, "GLDirect has not been configured.\n\n"
00587                               "Please run the configuration program\n"
00588                               "before using GLDirect with applications.\n",
00589                               "GLDirect", MB_OK | MB_ICONWARNING);
00590             bWarnOnce = TRUE;
00591             return FALSE;
00592         }
00593 
00594 #ifdef _USE_GLD3_WGL
00595         // Must do this as early as possible.
00596         // Need to read regkeys/ini-file first though.
00597         gldInitDriverPointers(glb.dwDriver);
00598 
00599         // Create private driver globals
00600         _gldDriver.CreatePrivateGlobals();
00601 #endif
00602         // Overide settings with application customizations
00603         if (glb.bAppCustomizations)
00604             dglSetAppCustomizations();
00605 
00606 //#ifndef _USE_GLD3_WGL
00607         // Set the global memory type to either sysmem or vidmem
00608         glb.dwMemoryType = glb.bHardware ? DDSCAPS_VIDEOMEMORY : DDSCAPS_SYSTEMMEMORY;
00609 //#endif
00610 
00611         // Multi-threaded support overides persistant display support
00612         if (glb.bMultiThreaded)
00613             glb.bDirectDrawPersistant = glb.bPersistantBuffers = FALSE;
00614 
00615         // Multi-threaded support needs to be reflected in Mesa code. (DaveM)
00616         _gld_bMultiThreaded = glb.bMultiThreaded;
00617 
00618         // Start logging
00619         ddlogPathOption(szLogPath);
00620         ddlogWarnOption(glb.bMessageBoxWarnings);
00621         ddlogOpen((DDLOG_loggingMethodType)dwLogging,
00622                   (DDLOG_severityType)dwDebugLevel);
00623 
00624         // Obtain the name of the calling app
00625         ddlogMessage(DDLOG_SYSTEM, "Driver           : SciTech GLDirect 4.0\n");
00626         GetModuleFileName(NULL, szExeName, sizeof(szExeName));
00627         ddlogPrintf(DDLOG_SYSTEM, "Executable       : %s", szExeName);
00628 
00629         ddlogPrintf(DDLOG_SYSTEM, "DirectDraw device: %s", glb.szDDName);
00630         ddlogPrintf(DDLOG_SYSTEM, "Direct3D driver  : %s", glb.szD3DName);
00631 
00632         ddlogPrintf(DDLOG_SYSTEM, "Rendering type   : %s", szRendering[glb.dwRendering]);
00633 
00634         ddlogPrintf(DDLOG_SYSTEM, "Multithreaded    : %s", glb.bMultiThreaded ? "Enabled" : "Disabled");
00635         ddlogPrintf(DDLOG_SYSTEM, "Display resources: %s", glb.bDirectDrawPersistant ? "Persistant" : "Instanced");
00636         ddlogPrintf(DDLOG_SYSTEM, "Buffer resources : %s", glb.bPersistantBuffers ? "Persistant" : "Instanced");
00637 
00638         dglInitContextState();
00639         dglBuildPixelFormatList();
00640         //dglBuildTextureFormatList();
00641 
00642     // D3D callback driver is now successfully initialized
00643     bInitialized = TRUE;
00644     // D3D callback driver is now ready to be exited
00645     bExited = FALSE;
00646 
00647     return TRUE;
00648 }
00649 
00650 // ***********************************************************************
00651 
00652 void dglExitDriver(void)
00653 {
00654 
00655     // Only need to clean up once per instance:
00656     // May be called implicitly from DLL_PROCESS_DETACH,
00657     // or explicitly from DGL_exitDriver().
00658     if (bExited)
00659         return;
00660     bExited = TRUE;
00661 
00662     // DDraw objects may be invalid when DLL unloads.
00663 __try {
00664 
00665     // Clean-up sequence (moved from DLL_PROCESS_DETACH)
00666 #ifndef _USE_GLD3_WGL
00667     dglReleaseTextureFormatList();
00668 #endif
00669     dglReleasePixelFormatList();
00670     dglDeleteContextState();
00671 
00672 #ifdef _USE_GLD3_WGL
00673     _gldDriver.DestroyPrivateGlobals();
00674 #endif
00675 
00676 }
00677 __except(EXCEPTION_EXECUTE_HANDLER) {
00678         ddlogPrintf(DDLOG_WARN, "Exception raised in dglExitDriver.");
00679 }
00680 
00681     // Close the log file
00682     ddlogClose();
00683 }
00684 
00685 // ***********************************************************************
00686 
00687 int WINAPI DllMain(
00688     HINSTANCE hInstance,
00689     DWORD fdwReason,
00690     PVOID pvReserved)
00691 {
00692     switch (fdwReason) {
00693     case DLL_PROCESS_ATTACH:
00694         // Cache DLL instance handle
00695         hInstanceDll = hInstance;
00696 
00697         // Flag that callback driver has yet to be initialized
00698         bInitialized = bExited = FALSE;
00699 
00700 #ifndef _USE_GLD3_WGL
00701         // Init internal Mesa function pointers
00702         memset(&mesaFuncs, 0, sizeof(DGL_mesaFuncs));
00703 #endif // _USE_GLD3_WGL
00704 
00705         // Init defaults
00706         dglInitGlobals();
00707 
00708         // Defer rest of DLL initialization to 1st WGL function call
00709         break;
00710 
00711     case DLL_PROCESS_DETACH:
00712         // Call exit clean-up sequence
00713         dglExitDriver();
00714         break;
00715     }
00716 
00717     return TRUE;
00718 }
00719 
00720 // ***********************************************************************
00721 
00722 void APIENTRY DGL_exitDriver(void)
00723 {
00724     // Call exit clean-up sequence
00725     dglExitDriver();
00726 }
00727 
00728 // ***********************************************************************
00729 
00730 void APIENTRY DGL_reinitDriver(void)
00731 {
00732     // Force init sequence again
00733     bInitialized = bExited = FALSE;
00734     dglInitDriver();
00735 }
00736 
00737 // ***********************************************************************
00738 
00739 int WINAPI DllInitialize(
00740     HINSTANCE hInstance,
00741     DWORD fdwReason,
00742     PVOID pvReserved)
00743 {
00744     // Some Watcom compiled executables require this.
00745     return DllMain(hInstance, fdwReason, pvReserved);
00746 }
00747 
00748 // ***********************************************************************
00749 
00750 void DGL_LoadSplashScreen(int piReg, char* pszUser)
00751 {
00752     HINSTANCE           hSplashDll = NULL;
00753     LPDGLSPLASHSCREEN   dglSplashScreen = NULL;
00754     static BOOL         bOnce = FALSE;
00755     static int          iReg = 0;
00756     static char         szUser[255] = {"\0"};
00757 
00758     // Display splash screen at all?
00759     if (!bSplashScreen)
00760         return;
00761 
00762     // Only display splash screen once
00763     if (bOnce)
00764         return;
00765     bOnce = TRUE;
00766 
00767     // Make local copy of string for passing to DLL
00768     if (pszUser)
00769         strcpy(szUser, pszUser);
00770     iReg = piReg;
00771 
00772     // Load Splash Screen DLL
00773     // (If it fails to load for any reason, we don't care...)
00774     hSplashDll = LoadLibrary("gldsplash.dll");
00775     if (hSplashDll) {
00776         // Execute the Splash Screen function
00777         dglSplashScreen = (LPDGLSPLASHSCREEN)GetProcAddress(hSplashDll, "GLDSplashScreen");
00778         if (dglSplashScreen)
00779             (*dglSplashScreen)(1, iReg, szUser);
00780         // Don't unload the DLL since splash screen dialog is modeless now
00781         }
00782 }
00783 
00784 // ***********************************************************************
00785 
00786 BOOL dglValidate()
00787 {
00788     char *szCaption = "SciTech GLDirect Driver";
00789     UINT uType = MB_OK | MB_ICONEXCLAMATION;
00790 
00791 #ifdef _USE_GLD3_WGL
00792     // (Re)build pixelformat list
00793     if (glb.bPixelformatsDirty)
00794         _gldDriver.BuildPixelformatList();
00795 #endif
00796 
00797     // Check to see if we have already validated
00798     if (bDriverValidated && bInitialized)
00799         return TRUE;
00800 
00801     // Since all (most) the WGL functions must be validated at this point,
00802     // this also insure that the callback driver is completely initialized.
00803     if (!bInitialized)
00804         if (!dglInitDriver()) {
00805             MessageBox(NULL,
00806                 "The GLDirect driver could not initialize.\n\n"
00807                 "Please run the configuration program to\n"
00808                 "properly configure the driver, or else\n"
00809                 "re-run the installation program.", szCaption, uType);
00810             _exit(1); // Bail
00811         }
00812 
00813     return TRUE;
00814 }
00815 
00816 // ***********************************************************************
00817 

Generated on Sun May 27 2012 04:19:59 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.