Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

GMain.c

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  GMain.c                                                                             */
00003 /*                                                                                      */
00004 /*  Author: John Pollard                                                                */
00005 /*  Description: Glide initialization code, etc                                         */
00006 /*                                                                                      */
00007 /*  The contents of this file are subject to the Genesis3D Public License               */
00008 /*  Version 1.01 (the "License"); you may not use this file except in                   */
00009 /*  compliance with the License. You may obtain a copy of the License at                */
00010 /*  http://www.genesis3d.com                                                            */
00011 /*                                                                                      */
00012 /*  Software distributed under the License is distributed on an "AS IS"                 */
00013 /*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
00014 /*  the License for the specific language governing rights and limitations              */
00015 /*  under the License.                                                                  */
00016 /*                                                                                      */
00017 /*  The Original Code is Genesis3D, released March 25, 1999.                            */
00018 /*Genesis3D Version 1.1 released November 15, 1999                            */
00019 /*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
00020 /*                                                                                      */
00021 /****************************************************************************************/
00022 #include <Windows.h>
00023 #include <StdIO.h>
00024 #include <Assert.h>
00025 
00026 #include "GlideDrv.h"
00027 #include "GMain.h"
00028 #include "GCache.h"
00029 #include "Glide.h"
00030 #include "GTHandle.h"
00031 
00032 int WriteBMP(unsigned short *ScreenBuffer, const char *Name);
00033 
00034 GrChipID_t                      TMU[3];                                 // TMU map number table
00035 
00036 DRV_Window                      ClientWindow;
00037 
00038 static RECT                     OldWindow;
00039 
00040 GMain_BoardInfo         g_BoardInfo;                    // Global board info for current hardware
00041 
00042 geBoolean                       g_FogEnable = GE_TRUE;
00043 geFloat                         g_FogR;
00044 geFloat                         g_FogG;
00045 geFloat                         g_FogB;
00046 
00047 //==============================================================================
00048 //==============================================================================
00049 geBoolean GMain_Startup(DRV_DriverHook *Hook)
00050 {
00051  
00052         int32                   VidMode;
00053 
00054         //SetEnvironmentVariable("SST_GAMMA", "1.0");
00055 
00056         switch(Hook->Mode)
00057         {
00058                 case 0:
00059                 {
00060                         ClientWindow.Width = 512;
00061                         ClientWindow.Height = 384;
00062                         VidMode = GR_RESOLUTION_512x384;
00063                         break;
00064                 }
00065                 case 1:
00066                 {
00067                         ClientWindow.Width = 640;
00068                         ClientWindow.Height = 480;
00069                         VidMode = GR_RESOLUTION_640x480;
00070                         break;
00071                 }
00072                 case 2:
00073                 {
00074                         ClientWindow.Width = 800;
00075                         ClientWindow.Height = 600;
00076                         VidMode = GR_RESOLUTION_800x600;
00077                         break;
00078                 }
00079                 case 3:
00080                 {
00081                         ClientWindow.Width = 1024;
00082                         ClientWindow.Height = 768;
00083                         VidMode = GR_RESOLUTION_1024x768;
00084                         break;
00085                 }
00086                 default:
00087                 {
00088                         SetLastDrvError(DRV_ERROR_NULL_WINDOW, "GLIDE_DrvInit:  Invalid display mode.");
00089                         return FALSE;
00090                 }
00091         }
00092 
00093         ClientWindow.hWnd = Hook->hWnd;
00094 
00095         // Go full-screen so we won't lose the mouse
00096         {
00097                 RECT    DeskTop;
00098 
00099                 // Save the old window size
00100                 GetWindowRect(ClientWindow.hWnd, &OldWindow);
00101 
00102                 // Get the size of the desktop
00103                 GetWindowRect(GetDesktopWindow(), &DeskTop);
00104 
00105                 // Resize the window to the size of the desktop
00106                 MoveWindow(ClientWindow.hWnd, DeskTop.left-4, DeskTop.top-40, DeskTop.right+20, DeskTop.bottom+20, TRUE);
00107 
00108                 // Center the mouse
00109                 SetCursorPos(ClientWindow.Width / 2, ClientWindow.Height / 2);
00110         }
00111 
00112         // initialize the Glide library 
00113         grGlideInit();
00114 
00115         // Get the info about this board
00116         if (!GMain_GetBoardInfo(&g_BoardInfo))
00117                 return FALSE;
00118 
00119         if (g_BoardInfo.NumTMU <= 0)
00120         {
00121                 SetLastDrvError(DRV_ERROR_INIT_ERROR, "GLIDE_DrvInit:  Not enough texture mapping units.");
00122                 return GE_FALSE;
00123         }
00124 
00125         // select the current graphics system 
00126         grSstSelect(0);
00127 
00128         // initialize and open the graphics system 
00129         if (!grSstWinOpen( (U32)ClientWindow.hWnd,
00130               VidMode,
00131               GR_REFRESH_60Hz,
00132               GR_COLORFORMAT_ABGR,
00133               GR_ORIGIN_UPPER_LEFT,
00134               2, 1 ))
00135         {
00136                 SetLastDrvError(DRV_ERROR_INIT_ERROR, "GLIDE_DrvInit:  grSstWinOpen failed.");
00137                 return GE_FALSE;
00138         }
00139 
00140         // We know that GLIDE will be in 5-6-5 mode...
00141         ClientWindow.R_shift = 5+6;
00142         ClientWindow.G_shift = 5;
00143         ClientWindow.B_shift = 0;
00144 
00145         ClientWindow.R_mask = 0xf800;
00146         ClientWindow.G_mask = 0x07e0;
00147         ClientWindow.B_mask = 0x001f;
00148 
00149         ClientWindow.R_width = 5;
00150         ClientWindow.G_width = 6;
00151         ClientWindow.B_width = 5;
00152 
00153         SetLastDrvError(DRV_ERROR_NONE, "GMain_Startup:  No error.");
00154 
00155         if (!GTHandle_Startup())
00156         {
00157                 SetLastDrvError(DRV_ERROR_GENERIC, "GMain_Startup:  GTHandle_Startup failed...\n");
00158                 return GE_FALSE;
00159         }
00160         
00161         if (!GMain_InitGlideRegisters())
00162         {
00163                 SetLastDrvError(DRV_ERROR_GENERIC, "GMain_Startup:  GMain_InitGlideRegisters failed...\n");
00164                 return GE_FALSE;
00165         }
00166 
00167         // Init the 3d display
00168         //grSstControl(GR_CONTROL_ACTIVATE);
00169         grGammaCorrectionValue(1.0f);
00170 
00171         return GE_TRUE;
00172 }
00173 
00174 //==================================================================================
00175 //      GMain_Shutdown
00176 //==================================================================================
00177 void GMain_Shutdown(void)
00178 {
00179         GTHandle_Shutdown();
00180 
00181         // Resize the window to the size of the original size
00182         MoveWindow(ClientWindow.hWnd, OldWindow.left, OldWindow.top, OldWindow.right, OldWindow.bottom, TRUE);
00183 
00184         grGlideShutdown();
00185 }
00186 
00187 //==================================================================================
00188 //      GMain_GetBoardInfo
00189 //      Glide is assumed to be initialized before this function is called...
00190 //==================================================================================
00191 geBoolean GMain_GetBoardInfo(GMain_BoardInfo *Info)
00192 {
00193         GrHwConfiguration       GlideHwConfig;
00194 
00195         // detect the Voodoo Graphics hardware in the host system
00196         if (!grSstQueryHardware(&GlideHwConfig))
00197         {
00198                 SetLastDrvError(DRV_ERROR_GENERIC, "GMain_GetBoardInfo:  grSstQueryHardware failed.");
00199                 return GE_FALSE;
00200         }
00201 
00202         memset(Info, 0, sizeof(*Info));
00203 
00204         switch (GlideHwConfig.SSTs[0].type)
00205         {
00206                 case GR_SSTTYPE_VOODOO:
00207 
00208                         Info->MainRam = GlideHwConfig.SSTs[0].sstBoard.VoodooConfig.fbRam;
00209                         Info->NumTMU = GlideHwConfig.SSTs[0].sstBoard.VoodooConfig.nTexelfx;
00210                         break;
00211 
00212                 case GR_SSTTYPE_SST96:
00213                         Info->MainRam = GlideHwConfig.SSTs[0].sstBoard.SST96Config.fbRam;
00214                         Info->NumTMU = GlideHwConfig.SSTs[0].sstBoard.SST96Config.nTexelfx;
00215                         break;
00216 
00217                 case GR_SSTTYPE_AT3D:
00218                         SetLastDrvError(DRV_ERROR_GENERIC, "GMain_GetBoardInfo:  GR_SSTTYPE_AT3D not supported.");
00219                         return GE_FALSE;
00220 
00221                 case GR_SSTTYPE_Voodoo2:
00222                         Info->MainRam = GlideHwConfig.SSTs[0].sstBoard.Voodoo2Config.fbRam;
00223                         Info->NumTMU = GlideHwConfig.SSTs[0].sstBoard.Voodoo2Config.nTexelfx;
00224                         break;
00225         }
00226 
00227 #if 0
00228         Info->NumTMU = 1;
00229 #endif
00230 
00231         return GE_TRUE;
00232 }
00233 
00234 static GrFog_t FogTable[GR_FOG_TABLE_SIZE];
00235 
00236 //==================================================================================
00237 //      GMain_InitGlideRegisters
00238 //==================================================================================
00239 geBoolean GMain_InitGlideRegisters(void)
00240 {
00241         //
00242         // Setup card register states
00243         //
00244 
00245         // fix up the z-buffer
00246         grDepthBufferMode( GR_DEPTHBUFFER_ZBUFFER );
00247         grDepthBufferFunction( GR_CMP_GEQUAL );
00248         grDepthMask( FXTRUE );
00249         
00250         // Fixup the transparent color
00251         grChromakeyMode(GR_CHROMAKEY_DISABLE);                  // Off by default, on for decals though...
00252         grChromakeyValue(1);
00253 
00254         // Fixup the Mipmapping 
00255         //      TMU
00256         //      Bias                    -32...+31
00257         //      Detail scale    0...7
00258         //      Detail Max              0...1.0
00259         grTexDetailControl(TMU[0], 0, 1, 1.0f);
00260 
00261         // -8... 7.75
00262         grTexLodBiasValue(TMU[0], -1.0f);
00263         //grTexLodBiasValue(TMU[0], 7.0f);
00264 
00265         // Tell it how we like it...
00266         guColorCombineFunction( GR_COLORCOMBINE_DECAL_TEXTURE );
00267 
00268         guTexCombineFunction( TMU[0], GR_TEXTURECOMBINE_DECAL );
00269         
00270         //rTexMipMapMode( TMU[0], GR_MIPMAP_NEAREST, FXFALSE);
00271         //grTexMipMapMode( TMU[0], GR_MIPMAP_DISABLE, FXFALSE );
00272 
00273         //grTexFilterMode( TMU[0], GR_TEXTUREFILTER_POINT_SAMPLED,GR_TEXTUREFILTER_BILINEAR);
00274         //grTexFilterMode( TMU[0], GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_POINT_SAMPLED);
00275         grTexFilterMode( TMU[0], GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR);
00276         grTexClampMode( TMU[0], GR_TEXTURECLAMP_WRAP,GR_TEXTURECLAMP_WRAP);
00277 
00278     grTexCombine( TMU[0],
00279                   GR_COMBINE_FUNCTION_LOCAL,
00280                   GR_COMBINE_FACTOR_NONE,
00281                   GR_COMBINE_FUNCTION_LOCAL,
00282                   GR_COMBINE_FACTOR_NONE,
00283                   FXFALSE, FXFALSE );
00284         
00285         
00286         // turn on gouraud shading
00287         grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
00288                                         GR_COMBINE_FACTOR_LOCAL,
00289                                         GR_COMBINE_LOCAL_ITERATED,
00290                                         GR_COMBINE_OTHER_TEXTURE,
00291                                         FXFALSE );
00292         
00293         
00294         grAlphaCombine( GR_COMBINE_FUNCTION_BLEND_OTHER,
00295                                         GR_COMBINE_FACTOR_LOCAL_ALPHA,
00296                                         GR_COMBINE_LOCAL_ITERATED,
00297                                         GR_COMBINE_OTHER_TEXTURE,
00298                                         FXFALSE );
00299         
00300         /*
00301         grAlphaCombine( GR_COMBINE_FUNCTION_LOCAL,
00302                     GR_COMBINE_FACTOR_LOCAL,
00303                     GR_COMBINE_LOCAL_ITERATED,
00304                     GR_COMBINE_OTHER_TEXTURE,
00305                     FXFALSE );
00306         */
00307 
00308         //grAlphaControlsITRGBLighting(FXTRUE);
00309         //grGlideShamelessPlug(FXTRUE);
00310 
00311         if (g_BoardInfo.NumTMU >= 2)
00312         {
00313                 grTexDetailControl(TMU[1], 0, 1, 0.3f);
00314                 grTexLodBiasValue(TMU[1], 0.3f);
00315 
00316                 guTexCombineFunction( TMU[1], GR_TEXTURECOMBINE_DECAL );
00317         
00318                 grTexFilterMode( TMU[1], GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR);
00319                 grTexClampMode( TMU[1], GR_TEXTURECLAMP_CLAMP,GR_TEXTURECLAMP_CLAMP);
00320 
00321                 grTexCombine(   TMU[1], 
00322                                                 GR_COMBINE_FUNCTION_SCALE_OTHER, 
00323                                                 GR_COMBINE_FACTOR_LOCAL,
00324                                                 GR_COMBINE_FUNCTION_SCALE_OTHER, 
00325                                                 GR_COMBINE_FACTOR_LOCAL,
00326                                                 FXFALSE, FXFALSE ); 
00327 
00328                 // Always texture clamp on second TMU (it only uses lightmaps for now)
00329                 grTexClampMode(TMU[1], GR_TEXTURECLAMP_CLAMP,GR_TEXTURECLAMP_CLAMP);
00330 
00331                 grHints(GR_HINT_STWHINT, GR_STWHINT_ST_DIFF_TMU0 | GR_STWHINT_ST_DIFF_TMU1);
00332         }
00333 
00334         //GMain_SetFogEnable(GE_TRUE, 0.0f, 255.0f, 0.0f, 500.0f, 1500.0f);
00335         GMain_SetFogEnable(GE_FALSE, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
00336 
00337         return GE_TRUE;
00338 }
00339 
00340 extern uint32                           CurrentLRU;             // Shame!!!
00341 
00342 //==================================================================================
00343 //      Reset the 3dfx, and free all allocated ram
00344 //==================================================================================
00345 geBoolean GMain_ResetAll(void)
00346 {
00347         GTHandle_Shutdown();
00348 
00349         if (!GTHandle_Startup())
00350                 return GE_FALSE;
00351         
00352         if (!GMain_InitGlideRegisters())
00353                 return GE_FALSE;
00354 
00355         CurrentLRU = 0;
00356 
00357         return GE_TRUE;
00358 }       
00359 
00360 //==================================================================================
00361 //==================================================================================
00362 geBoolean DRIVERCC GMain_ScreenShot(const char *Name)
00363 {
00364         uint16          *Buffer;
00365         
00366         Buffer = (uint16*)malloc(sizeof(uint16*)*ClientWindow.Width*ClientWindow.Height);
00367         
00368         if (!grLfbReadRegion(GR_BUFFER_FRONTBUFFER,0,0,ClientWindow.Width,ClientWindow.Height,
00369                 ClientWindow.Width*2, (void*)Buffer))
00370         {
00371                 SetLastDrvError(DRV_ERROR_GENERIC, "GLIDE: Could not save BMP.");
00372                 return FALSE;
00373         }
00374         
00375         WriteBMP(Buffer, Name, ClientWindow.Width, ClientWindow.Height);
00376 
00377         free(Buffer);
00378 
00379         return GE_TRUE;
00380 }
00381 
00382 //==================================================================================
00383 //      GMain_SetFogEnable
00384 //==================================================================================
00385 geBoolean DRIVERCC GMain_SetFogEnable(geBoolean Enable, geFloat r, geFloat g, geFloat b, geFloat Start, geFloat End)
00386 {
00387         g_FogEnable = Enable;
00388         g_FogR = r;
00389         g_FogG = g;
00390         g_FogB = b;
00391 
00392         if (g_FogEnable)
00393         {
00394                 grFogMode(GR_FOG_WITH_TABLE); 
00395                 grFogColorValue(((uint32)b<<16)|((uint32)g<<8)|(uint32)r);
00396                 guFogGenerateLinear(FogTable, Start, End); 
00397                 grFogTable(FogTable);
00398         }
00399         else
00400         {
00401                 grFogMode(GR_FOG_DISABLE);
00402         }
00403 
00404         return GE_TRUE;
00405 }

Generated on Tue Sep 30 12:35:53 2003 for GTestAndEngine by doxygen 1.3.2