//============================================================================================ // SetupCurrent3dDesc //============================================================================================ geBoolean SetupCurrent3dDesc(gePixelFormat PixelFormat) { switch (PixelFormat) { case GE_PIXELFORMAT_16BIT_555_RGB: case GE_PIXELFORMAT_16BIT_565_RGB: { memcpy(&CurrentSurfDesc, &AppInfo.ddTexFormat, sizeof(DDSURFACEDESC2)); break; } case GE_PIXELFORMAT_16BIT_4444_ARGB: { memcpy(&CurrentSurfDesc, &AppInfo.ddFourBitAlphaSurfFormat, sizeof(DDSURFACEDESC2)); break; } case GE_PIXELFORMAT_16BIT_1555_ARGB: { memcpy(&CurrentSurfDesc, &AppInfo.ddOneBitAlphaSurfFormat, sizeof(DDSURFACEDESC2)); break; } default: { SetLastDrvError(DRV_ERROR_GENERIC, "SetupCurrent3dDesc: Invalid pixel format.\n"); return GE_FALSE; } } return GE_TRUE; }
//================================================================================== // GMain_GetBoardInfo // Glide is assumed to be initialized before this function is called... //================================================================================== geBoolean GMain_GetBoardInfo(GMain_BoardInfo *Info) { GrHwConfiguration GlideHwConfig; // detect the Voodoo Graphics hardware in the host system if (!grSstQueryHardware(&GlideHwConfig)) { SetLastDrvError(DRV_ERROR_GENERIC, "GMain_GetBoardInfo: grSstQueryHardware failed."); return GE_FALSE; } memset(Info, 0, sizeof(*Info)); switch (GlideHwConfig.SSTs[0].type) { case GR_SSTTYPE_VOODOO: Info->MainRam = GlideHwConfig.SSTs[0].sstBoard.VoodooConfig.fbRam; Info->NumTMU = GlideHwConfig.SSTs[0].sstBoard.VoodooConfig.nTexelfx; break; case GR_SSTTYPE_SST96: Info->MainRam = GlideHwConfig.SSTs[0].sstBoard.SST96Config.fbRam; Info->NumTMU = GlideHwConfig.SSTs[0].sstBoard.SST96Config.nTexelfx; break; case GR_SSTTYPE_AT3D: SetLastDrvError(DRV_ERROR_GENERIC, "GMain_GetBoardInfo: GR_SSTTYPE_AT3D not supported."); return GE_FALSE; case GR_SSTTYPE_Voodoo2: Info->MainRam = GlideHwConfig.SSTs[0].sstBoard.Voodoo2Config.fbRam; Info->NumTMU = GlideHwConfig.SSTs[0].sstBoard.Voodoo2Config.nTexelfx; break; } #if 0 Info->NumTMU = 1; #endif return GE_TRUE; }
//============================================================================================ // THandle_Create //============================================================================================ geRDriver_THandle *DRIVERCC THandle_Create(int32 Width, int32 Height, int32 NumMipLevels, const geRDriver_PixelFormat *PixelFormat) { geRDriver_THandle *THandle; THandle = FindTextureHandle(); if (!THandle) { SetLastDrvError(DRV_ERROR_GENERIC, "D3DDRV:THandle_Create: Out of texture handles.\n"); return NULL; } THandle->PixelFormat = *PixelFormat; if (PixelFormat->Flags & RDRIVER_PF_3D) { // Get the pixel format desc for this thandle if (!SetupCurrent3dDesc(PixelFormat->PixelFormat)) return NULL; if (!Create3DTHandle(THandle, Width, Height, NumMipLevels, PixelFormat)) return NULL; CacheNeedsUpdate = GE_TRUE; } else if (PixelFormat->Flags & RDRIVER_PF_LIGHTMAP) { // Get the pixel format desc for this thandle if (!SetupCurrent3dDesc(PixelFormat->PixelFormat)) return NULL; if (!CreateLightmapTHandle(THandle, Width, Height, NumMipLevels, PixelFormat)) return NULL; CacheNeedsUpdate = GE_TRUE; } else if (PixelFormat->Flags & RDRIVER_PF_2D) { // 2d surfaces are always this format for now memcpy(&CurrentSurfDesc, &AppInfo.ddSurfFormat, sizeof(DDSURFACEDESC2)); if (!Create2DTHandle(THandle, Width, Height, NumMipLevels, PixelFormat)) return NULL; } return THandle; }
//================================================================================== //================================================================================== geBoolean DRIVERCC GMain_ScreenShot(const char *Name) { uint16 *Buffer; Buffer = (uint16*)malloc(sizeof(uint16*)*ClientWindow.Width*ClientWindow.Height); if (!grLfbReadRegion(GR_BUFFER_FRONTBUFFER,0,0,ClientWindow.Width,ClientWindow.Height, ClientWindow.Width*2, (void*)Buffer)) { SetLastDrvError(DRV_ERROR_GENERIC, "GLIDE: Could not save BMP."); return FALSE; } WriteBMP(Buffer, Name, ClientWindow.Width, ClientWindow.Height); free(Buffer); return GE_TRUE; }
//============================================================================================ // FindTextureHandle //============================================================================================ geRDriver_THandle *FindTextureHandle(void) { int32 i; geRDriver_THandle *pHandle; pHandle = TextureHandles; for (i=0; i< MAX_TEXTURE_HANDLES; i++, pHandle++) { if (!pHandle->Active) { memset(pHandle, 0, sizeof(geRDriver_THandle)); pHandle->Active = 1; return pHandle; } } SetLastDrvError(DRV_ERROR_GENERIC, "D3D_FindTextureHandle: No more handles left.\n"); return NULL; }
//============================================================================== //============================================================================== geBoolean GMain_Startup(DRV_DriverHook *Hook) { int32 VidMode; //SetEnvironmentVariable("SST_GAMMA", "1.0"); switch(Hook->Mode) { case 0: { ClientWindow.Width = 512; ClientWindow.Height = 384; VidMode = GR_RESOLUTION_512x384; break; } case 1: { ClientWindow.Width = 640; ClientWindow.Height = 480; VidMode = GR_RESOLUTION_640x480; break; } case 2: { ClientWindow.Width = 800; ClientWindow.Height = 600; VidMode = GR_RESOLUTION_800x600; break; } case 3: { ClientWindow.Width = 1024; ClientWindow.Height = 768; VidMode = GR_RESOLUTION_1024x768; break; } default: { SetLastDrvError(DRV_ERROR_NULL_WINDOW, "GLIDE_DrvInit: Invalid display mode."); return FALSE; } } ClientWindow.hWnd = Hook->hWnd; // Go full-screen so we won't lose the mouse { RECT DeskTop; // Save the old window size GetWindowRect(ClientWindow.hWnd, &OldWindow); // Get the size of the desktop GetWindowRect(GetDesktopWindow(), &DeskTop); // Resize the window to the size of the desktop MoveWindow(ClientWindow.hWnd, DeskTop.left-4, DeskTop.top-40, DeskTop.right+20, DeskTop.bottom+20, TRUE); // Center the mouse SetCursorPos(ClientWindow.Width / 2, ClientWindow.Height / 2); } // initialize the Glide library grGlideInit(); // Get the info about this board if (!GMain_GetBoardInfo(&g_BoardInfo)) return FALSE; if (g_BoardInfo.NumTMU <= 0) { SetLastDrvError(DRV_ERROR_INIT_ERROR, "GLIDE_DrvInit: Not enough texture mapping units."); return GE_FALSE; } // select the current graphics system grSstSelect(0); // initialize and open the graphics system if (!grSstWinOpen( (U32)ClientWindow.hWnd, VidMode, GR_REFRESH_60Hz, GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1 )) { SetLastDrvError(DRV_ERROR_INIT_ERROR, "GLIDE_DrvInit: grSstWinOpen failed."); return GE_FALSE; } // We know that GLIDE will be in 5-6-5 mode... ClientWindow.R_shift = 5+6; ClientWindow.G_shift = 5; ClientWindow.B_shift = 0; ClientWindow.R_mask = 0xf800; ClientWindow.G_mask = 0x07e0; ClientWindow.B_mask = 0x001f; ClientWindow.R_width = 5; ClientWindow.G_width = 6; ClientWindow.B_width = 5; SetLastDrvError(DRV_ERROR_NONE, "GMain_Startup: No error."); if (!GTHandle_Startup()) { SetLastDrvError(DRV_ERROR_GENERIC, "GMain_Startup: GTHandle_Startup failed...\n"); return GE_FALSE; } if (!GMain_InitGlideRegisters()) { SetLastDrvError(DRV_ERROR_GENERIC, "GMain_Startup: GMain_InitGlideRegisters failed...\n"); return GE_FALSE; } // Init the 3d display //grSstControl(GR_CONTROL_ACTIVATE); grGammaCorrectionValue(1.0f); return GE_TRUE; }
// Create a new texture handle... geRDriver_THandle *DRIVERCC THandle_Create(int32 Width, int32 Height, int32 NumMipLevels, const geRDriver_PixelFormat *PixelFormat) { geRDriver_THandle *THandle; GLubyte Log; THandle = FindTextureHandle(); if (!THandle) { SetLastDrvError(DRV_ERROR_GENERIC, "OGL_THandleCreate: No more handles left."); gllog("ERROR: OGL_THandleCreate: No more handles left.\n"); goto ExitWithError; } if(PixelFormat->Flags & RDRIVER_PF_3D) { char errMsg[64]; if(Width > maxTextureSize) { sprintf(errMsg, "OGL_THandleCreate: Width > GL_MAX_TEXTURE_SIZE (%d)", maxTextureSize); SetLastDrvError(DRV_ERROR_GENERIC, errMsg); gllog("%s\n", errMsg); goto ExitWithError; } if (Height > maxTextureSize) { sprintf(errMsg, "OGL_THandleCreate: Height > GL_MAX_TEXTURE_SIZE (%d)", maxTextureSize); SetLastDrvError(DRV_ERROR_GENERIC, errMsg); gllog("%s\n", errMsg); goto ExitWithError; } } THandle->MipLevels = NumMipLevels; THandle->Width = Width; THandle->Height = Height; THandle->PixelFormat = *PixelFormat; THandle->Flags = 0; Log = (uint8)GetLog(Width, Height); if(THandle->PixelFormat.Flags & RDRIVER_PF_2D) { THandle->PaddedWidth = SnapToPower2(THandle->Width); THandle->PaddedHeight = SnapToPower2(THandle->Height); } else if(THandle->PixelFormat.Flags & RDRIVER_PF_3D) { THandle->InvScale = 1.0f / (GLfloat)((1<<Log)); } else { // Must be a lightmap THandle->Flags |= THANDLE_UPDATE_LM; THandle->InvScale = 1.0f / (GLfloat)((1<<Log)<<4); } // Init an OpenGL texture object to hold this texture glGenTextures(1, &(THandle->TextureID)); return THandle; ExitWithError: { return NULL; } }