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

register.c File Reference

#include <Windows.h>
#include <stdio.h>
#include <Assert.h>
#include "SoftDrv.h"
#include "DCommon.h"
#include "Register.h"
#include "Sal.h"
#include "ddraw.h"

Go to the source code of this file.

Functions

S32 SnapToPower2 (S32 Width)
S32 Log2 (S32 P2)
geRDriver_THandleFindTextureHandle ()
geBoolean FreeTextureHandle (geRDriver_THandle *THandle)
geBoolean FreeAllTextureHandles (void)
geRDriver_THandle *DRIVERCC CreateTexture (int32 Width, int32 Height, int32 NumMipLevels, const geRDriver_PixelFormat *PixelFormat)
geBoolean DRIVERCC THandle_GetInfo (geRDriver_THandle *THandle, int32 MipLevel, geRDriver_THandleInfo *Info)
geBoolean DRIVERCC SetPalette (geRDriver_THandle *THandle, geRDriver_THandle *PalHandle)
geRDriver_THandle *DRIVERCC GetPalette (geRDriver_THandle *THandle)
geBoolean DRIVERCC SetAlpha (geRDriver_THandle *THandle, geRDriver_THandle *AHandle)
geRDriver_THandle *DRIVERCC GetAlpha (geRDriver_THandle *THandle)
geBoolean DRIVERCC DestroyTexture (geRDriver_THandle *THandle)
geBoolean DRIVERCC LockTextureHandle (geRDriver_THandle *THandle, int32 MipLevel, void **Data)
geBoolean DRIVERCC UnLockTextureHandle (geRDriver_THandle *THandle, int32 MipLevel)
BOOL DRIVERCC DrvResetAll (void)
int Brighten (int Color)

Variables

geRDriver_THandle TextureHandles [MAX_TEXTURE_HANDLES]
CPUInfo ProcessorInfo


Function Documentation

int Brighten int  Color  )  [static]
 

Definition at line 370 of file register.c.

References geFloat.

00371 {
00372         Color   =(int)((geFloat)Color * 1.5f);
00373 
00374         return((Color > 255)? 255 : Color);
00375 }

geRDriver_THandle* DRIVERCC CreateTexture int32  Width,
int32  Height,
int32  NumMipLevels,
const geRDriver_PixelFormat PixelFormat
 

Definition at line 133 of file register.c.

References geRDriver_THandle::BitPtr, DRIVERCC, DRV_ERROR_GENERIC, FindTextureHandle(), geRDriver_PixelFormat::Flags, geRDriver_THandle::Flags, GE_PIXELFORMAT_16BIT_555_RGB, GE_PIXELFORMAT_16BIT_565_RGB, GE_PIXELFORMAT_24BIT_RGB, GE_PIXELFORMAT_32BIT_ARGB, GE_PIXELFORMAT_32BIT_XRGB, GE_PIXELFORMAT_8BIT, geRDriver_THandle::Height, int32, geRDriver_THandle::MipLevels, NULL, PixelFormat, geRDriver_THandle::PixelFormat, geRDriver_PixelFormat::PixelFormat, RDRIVER_PF_3D, RDRIVER_PF_CAN_DO_COLORKEY, RDRIVER_PF_PALETTE, SetLastDrvError(), SnapToPower2(), THANDLE_TRANS, U16, U32, U8, and geRDriver_THandle::Width.

00134 {
00135         int32                           i, SWidth, SHeight;                     // Snapped to power of 2 width/height
00136         geRDriver_THandle       *THandle;
00137 
00138         assert(PixelFormat);
00139         
00140         THandle = FindTextureHandle();
00141 
00142         if (!THandle)
00143         {
00144                 SetLastDrvError(DRV_ERROR_GENERIC, "SOFT_CreateTexture: No more handles left.");
00145                 goto ExitWithError;
00146         }
00147 
00148         if(PixelFormat->Flags & RDRIVER_PF_3D)
00149         {
00150                 if (Width > 256)
00151                 {
00152                         SetLastDrvError(DRV_ERROR_GENERIC, "SOFT_CreateTexture: Width > 256.");
00153                         goto ExitWithError;
00154                 }
00155 
00156                 if (Height > 256)
00157                 {
00158                         SetLastDrvError(DRV_ERROR_GENERIC, "SOFT_CreateTexture: Height > 256.");
00159                         goto ExitWithError;
00160                 }
00161                 SWidth = SnapToPower2(Width);
00162                 SHeight = SnapToPower2(Height);
00163 
00164                 if (Width != SWidth)
00165                 {
00166                         SetLastDrvError(DRV_ERROR_GENERIC, "SOFT_CreateTexture: Not a power of 2.");
00167                         goto ExitWithError;
00168                 }
00169 
00170                 if (Height != SHeight)
00171                 {
00172                         SetLastDrvError(DRV_ERROR_GENERIC, "SOFT_CreateTexture: Not a power of 2.");
00173                         goto ExitWithError;
00174                 }
00175         }
00176         
00177         THandle->MipLevels              =NumMipLevels;
00178         THandle->Width                  =Width;
00179         THandle->Height                 =Height;
00180         THandle->PixelFormat    =*PixelFormat;
00181         THandle->Flags                  =0;
00182 
00183         for(i=0;i < NumMipLevels;i++)
00184         {
00185                 if(PixelFormat->Flags & RDRIVER_PF_PALETTE)
00186                 {
00187                         if( PixelFormat->PixelFormat == GE_PIXELFORMAT_32BIT_ARGB ||
00188                                 PixelFormat->PixelFormat == GE_PIXELFORMAT_32BIT_XRGB ) // <> CB added XRGB
00189                         {
00190                                 THandle->BitPtr[i]      =(U16 *)malloc(sizeof(U32) * Width * Height);
00191                         }
00192                         else
00193                         {
00194                                 SetLastDrvError(DRV_ERROR_GENERIC, "SOFT_CreateTexture: Bad Pal format.");
00195                                 goto ExitWithError;
00196                         }
00197                 }
00198                 else
00199                 {
00200                         switch (PixelFormat->PixelFormat)
00201                         {
00202                                 case GE_PIXELFORMAT_16BIT_565_RGB:
00203                                 {
00204                                         THandle->BitPtr[i]      =(U16 *)malloc(sizeof(U16) * Width * Height);
00205                                         break;
00206                                 }
00207                                 
00208                                 case GE_PIXELFORMAT_16BIT_555_RGB:
00209                                 {
00210                                         THandle->BitPtr[i]      =(U16 *)malloc(sizeof(U16) * Width * Height);
00211                                         break;
00212                                 }
00213 
00214                                 case GE_PIXELFORMAT_8BIT:
00215                                 {
00216                                         THandle->BitPtr[i]      =(U16 *)malloc(sizeof(U8) * Width * Height);
00217                                         break;
00218                                 }
00219 
00220                                 case GE_PIXELFORMAT_24BIT_RGB:
00221                                 {
00222                                         THandle->BitPtr[i]      =(U16 *)malloc((sizeof(U8)*3) * Width * Height);
00223                                         break;
00224                                 }
00225 
00226                                 default:
00227                                 {
00228                                         SetLastDrvError(DRV_ERROR_GENERIC, "SOFT_Create3DTexture: Invalid pixel format.");
00229                                         goto ExitWithError;
00230 //                                      THandle->BitPtr[i]      =(U16 *)malloc(sizeof(U16) * Width * Height);
00231 //                                      break;
00232                                 }
00233                         }
00234 
00235                         if ( PixelFormat->Flags & RDRIVER_PF_CAN_DO_COLORKEY )
00236                         {
00237                                 THandle->Flags |= THANDLE_TRANS;
00238                         }
00239                 }
00240         }
00241 
00242         return THandle;
00243                 
00244         ExitWithError:
00245         {
00246                 return NULL;
00247         }
00248 }

geBoolean DRIVERCC DestroyTexture geRDriver_THandle THandle  ) 
 

Definition at line 330 of file register.c.

References DRIVERCC, FreeTextureHandle(), and geBoolean.

00331 {
00332         return FreeTextureHandle(THandle);
00333 }

BOOL DRIVERCC DrvResetAll void   ) 
 

Definition at line 364 of file register.c.

References DRIVERCC, and FreeAllTextureHandles().

00365 {
00366         return  FreeAllTextureHandles();
00367 }

geRDriver_THandle* FindTextureHandle void   ) 
 

Definition at line 42 of file register.c.

References geRDriver_THandle::Active, GE_TRUE, int32, MAX_TEXTURE_HANDLES, NULL, and TextureHandles.

00043 {
00044         int32                           i;
00045         geRDriver_THandle       *THandle;
00046 
00047         THandle = TextureHandles;
00048 
00049         for (i=0; i< MAX_TEXTURE_HANDLES; i++, THandle++)
00050         {
00051                 if (!THandle->Active)
00052                 {
00053                         memset(THandle, 0, sizeof(geRDriver_THandle));
00054 
00055                         THandle->Active = GE_TRUE;
00056 
00057                         return THandle;
00058                 }
00059         }
00060 
00061         return NULL;
00062 }

geBoolean FreeAllTextureHandles void   ) 
 

Definition at line 109 of file register.c.

References geRDriver_THandle::Active, FreeTextureHandle(), GE_TRUE, geBoolean, int32, MAX_TEXTURE_HANDLES, and TextureHandles.

00110 {
00111         int32                           i;
00112         geRDriver_THandle       *pTHandle;
00113 
00114         pTHandle = TextureHandles;
00115 
00116 #ifdef _DEBUG
00117         OutputDebugString("FreeAllTextureHandles\n");
00118 #endif
00119 
00120         for (i=0; i< MAX_TEXTURE_HANDLES; i++, pTHandle++)
00121         {
00122                 if (!pTHandle->Active)
00123                 {
00124                         continue;
00125                 }
00126                 
00127                 FreeTextureHandle(pTHandle);
00128         }
00129 
00130         return GE_TRUE;
00131 }

geBoolean FreeTextureHandle geRDriver_THandle THandle  ) 
 

Definition at line 67 of file register.c.

References geRDriver_THandle::Active, geRDriver_THandle::AlphaHandle, geRDriver_THandle::BitPtr, GE_FALSE, GE_TRUE, geBoolean, CPUInfoTag::Has3DNow, geRDriver_THandle::MipLevels, NULL, geRDriver_THandle::PalHandle, and ProcessorInfo.

Referenced by DestroyTexture(), and FreeAllTextureHandles().

00068 {
00069         int     k;
00070 
00071         assert(THandle);
00072 //<>    assert(THandle->Active == GE_TRUE);
00073 
00074         if( ! THandle->Active )
00075         {
00076                 return  GE_FALSE;
00077         }
00078 
00079         if(THandle->PalHandle)
00080         {
00081                 FreeTextureHandle(THandle->PalHandle);
00082         }
00083 
00084         if(THandle->AlphaHandle)
00085         {
00086                 FreeTextureHandle(THandle->AlphaHandle);
00087         }
00088 
00089         for(k=0;k < THandle->MipLevels;k++)
00090         {
00091                 if(!ProcessorInfo.Has3DNow)
00092                 {
00093                         if(THandle->BitPtr[k])
00094                         {
00095                                 free(THandle->BitPtr[k]);
00096                         }
00097                 }                       
00098                 THandle->BitPtr[k]      =NULL;
00099         }
00100 
00101         memset(THandle, 0, sizeof(geRDriver_THandle));  
00102 
00103         return  GE_TRUE;
00104 }

geRDriver_THandle* DRIVERCC GetAlpha geRDriver_THandle THandle  ) 
 

Definition at line 319 of file register.c.

References geRDriver_THandle::Active, geRDriver_THandle::AlphaHandle, DRIVERCC, and GE_FALSE.

00320 {
00321         assert(THandle);
00322 #ifdef _DEBUG
00323         if ( ! THandle->Active )
00324                 return GE_FALSE;
00325 #endif
00326 
00327         return  THandle->AlphaHandle;
00328 }

geRDriver_THandle* DRIVERCC GetPalette geRDriver_THandle THandle  ) 
 

Definition at line 289 of file register.c.

References geRDriver_THandle::Active, DRIVERCC, GE_FALSE, and geRDriver_THandle::PalHandle.

00290 {
00291         assert(THandle);
00292 #ifdef _DEBUG
00293         if ( ! THandle->Active )
00294                 return GE_FALSE;
00295 #endif
00296 
00297         return  THandle->PalHandle;
00298 }

geBoolean DRIVERCC LockTextureHandle geRDriver_THandle THandle,
int32  MipLevel,
void **  Data
 

Definition at line 335 of file register.c.

References geRDriver_THandle::Active, geRDriver_THandle::BitPtr, DRIVERCC, geRDriver_THandle::Flags, GE_FALSE, GE_TRUE, geBoolean, THANDLE_LOCKED, and uint16.

00336 {
00337         assert(THandle);
00338         assert(MipLevel <= THandle->MipLevels && MipLevel >= 0);
00339 #ifdef _DEBUG
00340         if ( ! THandle->Active )
00341                 return GE_FALSE;
00342         if ( ! THandle->BitPtr[MipLevel] )
00343                 return GE_FALSE;
00344 #endif
00345 
00346         THandle->Flags  |=(THANDLE_LOCKED << MipLevel);
00347         *Data                   =(uint16*)THandle->BitPtr[MipLevel];
00348 
00349         return  GE_TRUE;
00350 }

S32 Log2 S32  P2  ) 
 

Definition at line 392 of file register.c.

References S32.

00393 {
00394         S32             p = 0;
00395         S32             i = 0;
00396         
00397         for (i = P2; (i&1) == 0; i>>=1)
00398                 p++;
00399 
00400         return p;
00401 }

geBoolean DRIVERCC SetAlpha geRDriver_THandle THandle,
geRDriver_THandle AHandle
 

Definition at line 300 of file register.c.

References geRDriver_THandle::Active, geRDriver_THandle::AlphaHandle, DRIVERCC, geRDriver_PixelFormat::Flags, GE_FALSE, GE_TRUE, geBoolean, geRDriver_THandle::PixelFormat, RDRIVER_PF_ALPHA, and RDRIVER_PF_HAS_ALPHA.

00301 {
00302         assert(THandle);
00303 #ifdef _DEBUG
00304         if ( ! THandle->Active )
00305                 return GE_FALSE;
00306 #endif
00307 
00308         if(THandle->PixelFormat.Flags & RDRIVER_PF_HAS_ALPHA)
00309         {
00310                 if(AHandle->PixelFormat.Flags & RDRIVER_PF_ALPHA)
00311                 {
00312                         THandle->AlphaHandle    =AHandle;
00313                         return  GE_TRUE;
00314                 }
00315         }
00316         return  GE_FALSE;
00317 }

geBoolean DRIVERCC SetPalette geRDriver_THandle THandle,
geRDriver_THandle PalHandle
 

Definition at line 279 of file register.c.

References DRIVERCC, GE_TRUE, geBoolean, and geRDriver_THandle::PalHandle.

00280 {
00281         assert(THandle);
00282 
00283         THandle->PalHandle      =PalHandle;
00284 
00285         return  GE_TRUE;
00286 }

S32 SnapToPower2 S32  Width  ) 
 

Definition at line 424 of file THandle.c.

References S32.

00425 {
00426         if(Width > 1 && Width <= 2) 
00427         {
00428                 Width = 2;
00429         }
00430         else if(Width > 2 && Width <= 4)
00431         {
00432                 Width = 4;
00433         }
00434         else if(Width > 4 && Width <= 8) 
00435         {
00436                 Width = 8;
00437         }
00438         else if(Width > 8 && Width <= 16)
00439         {
00440                 Width =16;
00441         }
00442         else if(Width > 16 && Width <= 32)
00443         {
00444                 Width = 32;
00445         }
00446         else if(Width > 32 && Width <= 64) 
00447         {
00448                 Width = 64;
00449         }
00450         else if(Width > 64 && Width <= 128) 
00451         {
00452                 Width = 128;
00453         }
00454         else if(Width > 128 && Width <= 256) 
00455         {
00456                 Width = 256;
00457         }
00458         else if(Width > 256 && Width <= 512) 
00459         {
00460                 Width = 512;
00461         }
00462         else if(Width > 512 && Width <= 1024) 
00463         {
00464                 Width = 1024;
00465         }
00466         else if(Width > 1024 && Width <= 2048) 
00467         {
00468                 Width = 2048;
00469         }
00470 
00471         return Width;
00472 }

geBoolean DRIVERCC THandle_GetInfo geRDriver_THandle THandle,
int32  MipLevel,
geRDriver_THandleInfo Info
 

Definition at line 250 of file register.c.

References geRDriver_THandle::Active, geRDriver_THandleInfo::ColorKey, DRIVERCC, geRDriver_THandle::Flags, geRDriver_THandleInfo::Flags, GE_FALSE, GE_TRUE, geBoolean, CPUInfoTag::Has3DNow, geRDriver_THandle::Height, geRDriver_THandleInfo::Height, geRDriver_THandle::PixelFormat, geRDriver_THandleInfo::PixelFormat, ProcessorInfo, RDRIVER_THANDLE_HAS_COLORKEY, geRDriver_THandleInfo::Stride, THANDLE_TRANS, geRDriver_THandle::Width, and geRDriver_THandleInfo::Width.

00251 {
00252         assert(THandle);
00253         assert(Info);
00254 #ifdef _DEBUG
00255         if ( ! THandle->Active )
00256                 return GE_FALSE;
00257 #endif
00258 
00259         Info->Width             = THandle->Width >> MipLevel;
00260         Info->Height    = THandle->Height >> MipLevel;
00261         Info->Stride    = Info->Width;
00262         Info->Flags     = 0;
00263         Info->PixelFormat       =THandle->PixelFormat;
00264 
00265         if ( ProcessorInfo.Has3DNow )
00266                 Info->ColorKey = 255;
00267         else
00268                 Info->ColorKey  = 1;
00269 
00270         if ( THandle->Flags & THANDLE_TRANS )
00271         {
00272                 Info->Flags |= RDRIVER_THANDLE_HAS_COLORKEY;
00273         }
00274 
00275         return  GE_TRUE;
00276 }

geBoolean DRIVERCC UnLockTextureHandle geRDriver_THandle THandle,
int32  MipLevel
 

Definition at line 352 of file register.c.

References DRIVERCC, geRDriver_THandle::Flags, GE_FALSE, GE_TRUE, geBoolean, THANDLE_LOCKED, and THANDLE_UPDATE.

00353 {
00354         assert(THandle);
00355         if (!(THandle->Flags & (THANDLE_LOCKED << MipLevel)))
00356                 return GE_FALSE;
00357 
00358         THandle->Flags  &=~(THANDLE_LOCKED << MipLevel);        // This mip is now unlocked
00359         THandle->Flags  |=THANDLE_UPDATE;                                       // Mark it for updating...
00360 
00361         return GE_TRUE;
00362 }


Variable Documentation

CPUInfo ProcessorInfo
 

Definition at line 37 of file register.c.

Referenced by AddSpanDraw(), BeginScene(), DrawDecal(), DrvInit(), EndScene(), EnumModes(), FreeTextureHandle(), GetCPUInfo(), RenderGouraudPoly(), RenderMiscTexturePoly(), RenderWorldPoly(), and THandle_GetInfo().

geRDriver_THandle TextureHandles[MAX_TEXTURE_HANDLES]
 

Definition at line 32 of file register.c.


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