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

GMain.c File Reference

#include <Windows.h>
#include <StdIO.h>
#include <Assert.h>
#include "GlideDrv.h"
#include "GMain.h"
#include "GCache.h"
#include "Glide.h"
#include "GTHandle.h"

Go to the source code of this file.

Functions

int WriteBMP (unsigned short *ScreenBuffer, const char *Name)
geBoolean GMain_Startup (DRV_DriverHook *Hook)
void GMain_Shutdown (void)
geBoolean GMain_GetBoardInfo (GMain_BoardInfo *Info)
geBoolean GMain_InitGlideRegisters (void)
geBoolean GMain_ResetAll (void)
geBoolean DRIVERCC GMain_ScreenShot (const char *Name)
geBoolean DRIVERCC GMain_SetFogEnable (geBoolean Enable, geFloat r, geFloat g, geFloat b, geFloat Start, geFloat End)

Variables

GrChipID_t TMU [3]
DRV_Window ClientWindow
RECT OldWindow
GMain_BoardInfo g_BoardInfo
geBoolean g_FogEnable = GE_TRUE
geFloat g_FogR
geFloat g_FogG
geFloat g_FogB
GrFog_t FogTable [GR_FOG_TABLE_SIZE]
uint32 CurrentLRU


Function Documentation

geBoolean GMain_GetBoardInfo GMain_BoardInfo Info  ) 
 

Definition at line 191 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

References DRV_ERROR_GENERIC, GE_FALSE, GE_TRUE, geBoolean, GlideHwConfig, GMain_BoardInfo::MainRam, GMain_BoardInfo::NumTMU, and SetLastDrvError().

Referenced by EnumSubDrivers(), and GMain_Startup().

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 }

geBoolean GMain_InitGlideRegisters void   ) 
 

Definition at line 239 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

References g_BoardInfo, GE_FALSE, GE_TRUE, geBoolean, GMain_SetFogEnable(), GMain_BoardInfo::NumTMU, and TMU.

Referenced by GMain_ResetAll(), and GMain_Startup().

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 }

geBoolean GMain_ResetAll void   ) 
 

Definition at line 345 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

References CurrentLRU, GE_FALSE, GE_TRUE, geBoolean, GMain_InitGlideRegisters(), GTHandle_Shutdown(), and GTHandle_Startup().

Referenced by DrvResetAll().

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 }       

geBoolean DRIVERCC GMain_ScreenShot const char *  Name  ) 
 

Definition at line 362 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

References ClientWindow, DRIVERCC, DRV_ERROR_GENERIC, FALSE, GE_TRUE, geBoolean, DRV_Window::Height, SetLastDrvError(), uint16, DRV_Window::Width, and WriteBMP().

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 }

geBoolean DRIVERCC GMain_SetFogEnable geBoolean  Enable,
geFloat  r,
geFloat  g,
geFloat  b,
geFloat  Start,
geFloat  End
 

Definition at line 385 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

References DRIVERCC, FogTable, g_FogB, g_FogEnable, g_FogG, g_FogR, GE_TRUE, geBoolean, r, and uint32.

Referenced by GMain_InitGlideRegisters().

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 }

void GMain_Shutdown void   ) 
 

Definition at line 177 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

References tagRECT::bottom, ClientWindow, GTHandle_Shutdown(), DRV_Window::hWnd, tagRECT::left, OldWindow, tagRECT::right, tagRECT::top, and TRUE.

Referenced by DrvShutdown().

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 }

geBoolean GMain_Startup DRV_DriverHook Hook  ) 
 

Definition at line 49 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

References DRV_Window::B_mask, DRV_Window::B_shift, DRV_Window::B_width, tagRECT::bottom, ClientWindow, DRV_ERROR_GENERIC, DRV_ERROR_INIT_ERROR, DRV_ERROR_NONE, DRV_ERROR_NULL_WINDOW, FALSE, g_BoardInfo, DRV_Window::G_mask, DRV_Window::G_shift, DRV_Window::G_width, GE_FALSE, GE_TRUE, geBoolean, GMain_GetBoardInfo(), GMain_InitGlideRegisters(), GTHandle_Startup(), DRV_Window::Height, DRV_Window::hWnd, DRV_DriverHook::hWnd, int32, tagRECT::left, DRV_DriverHook::Mode, GMain_BoardInfo::NumTMU, OldWindow, DRV_Window::R_mask, DRV_Window::R_shift, DRV_Window::R_width, tagRECT::right, SetLastDrvError(), tagRECT::top, TRUE, U32, VidMode, and DRV_Window::Width.

Referenced by DrvInit().

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 }

int WriteBMP unsigned short *  ScreenBuffer,
const char *  Name
 

Definition at line 66 of file Bmp.c.

References bfh, bi, BLUE, GREEN, HEIGHT, RED, WIDTH, and y.

Referenced by GMain_ScreenShot().

00067 {
00068         FILE *  out;
00069         int     y;
00070 
00071         out = fopen(Name, "wb");
00072 
00073         if (!out)
00074                 return 0;
00075 
00076         if      (fwrite(&bfh, sizeof(bfh), 1, out) != 1)
00077                 return 0;
00078 
00079         if      (fwrite(&bi, sizeof(bi), 1, out) != 1)
00080                 return 0;
00081 
00082         for     (y = HEIGHT-1; y >= 0; y--)
00083         {
00084                 int                     i;
00085                 unsigned short *p;
00086                 unsigned char   Buff[WIDTH * 3];
00087                 unsigned char * BuffPtr;
00088 
00089                 BuffPtr = &Buff[0];
00090                 p = &ScreenBuffer[y*WIDTH];
00091                 for     (i = 0; i < WIDTH; i++)
00092                 {
00093                         #ifdef BIT16
00094                                 unsigned short  c;
00095                         
00096                                 c = p[i];
00097                                 c = (RED(c) << 10) + (GREEN(c) << 5) + BLUE(c);
00098                                 p[i] = c;
00099                         #else
00100                                 
00101                                 #ifdef VER1
00102                                 char c[3];
00103                                 c = (char)(GREEN(p[i]) << 2);
00104                                 fwrite(&c, 1, 1, out);
00105                                 c = (char)(RED(p[i]) << 3);
00106                                 fwrite(&c, 1, 1, out);
00107                                 c = (char)(BLUE(p[i]) << 3);
00108                                 fwrite(&c, 1, 1, out);
00109                                 #else
00110                                 #if 0
00111                                 char c[3];
00112                                 c = (char)(BLUE(p[i]) << 3);
00113                                 fwrite(&c, 1, 1, out);
00114                                 c = (char)(GREEN(p[i]) << 2);
00115                                 fwrite(&c, 1, 1, out);
00116                                 c = (char)(RED(p[i]) << 3);
00117                                 fwrite(&c, 1, 1, out);
00118                                 #else
00119                                 *BuffPtr++ = (char)(BLUE(p[i]) << 3);
00120                                 *BuffPtr++ = (char)(GREEN(p[i]) << 2);
00121                                 *BuffPtr++ = (char)(RED(p[i]) << 3);
00122 //                              fwrite(&c[0], 3, 1, out);
00123                                 #endif
00124                                 #endif
00125                         #endif
00126                 }
00127 
00128                 fwrite(&Buff[0], WIDTH * 3, 1, out);
00129                 #ifdef BIT16
00130                         p = &ScreenBuffer[y*WIDTH];
00131                         for     (i = 0; i < WIDTH; i++)
00132                                 fwrite(&p[(i+2)%WIDTH], 2, 1, out);
00133                 #endif
00134         }
00135 
00136         if      (fclose(out))
00137                 return 0;
00138 
00139         return 1;
00140 }


Variable Documentation

DRV_Window ClientWindow
 

Definition at line 36 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

uint32 CurrentLRU
 

Definition at line 340 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

GrFog_t FogTable[GR_FOG_TABLE_SIZE] [static]
 

Definition at line 234 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

Referenced by GMain_SetFogEnable().

GMain_BoardInfo g_BoardInfo
 

Definition at line 40 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

Referenced by EnumModes(), EnumSubDrivers(), GMain_InitGlideRegisters(), GMain_Startup(), GTHandle_Startup(), Render_SetHardwareMode(), Render_SetTexCombine(), and Render_WorldPoly().

geFloat g_FogB
 

Definition at line 45 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

Referenced by BeginScene(), and GMain_SetFogEnable().

geBoolean g_FogEnable = GE_TRUE
 

Definition at line 42 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

Referenced by BeginScene(), GMain_SetFogEnable(), and Render_SetHardwareMode().

geFloat g_FogG
 

Definition at line 44 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

Referenced by BeginScene(), and GMain_SetFogEnable().

geFloat g_FogR
 

Definition at line 43 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

Referenced by BeginScene(), and GMain_SetFogEnable().

RECT OldWindow [static]
 

Definition at line 38 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

Referenced by GMain_Shutdown(), and GMain_Startup().

GrChipID_t TMU[3]
 

Definition at line 34 of file Genesis3D v1-6/G3D/Engine/Drivers/GlideDrv/GMain.c.

Referenced by GMain_InitGlideRegisters(), GTHandle_Startup(), Render_SetHardwareMode(), Render_SetTexCombine(), Render_WorldPoly(), RenderLightmapPoly(), and SetupTexture().


Generated on Tue Sep 30 12:37:40 2003 for GTestAndEngine by doxygen 1.3.2