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

THandle.cpp File Reference

#include <Windows.h>
#include <DDraw.h>
#include <D3D.h>
#include "THandle.h"
#include "BaseType.h"
#include "D3DDrv7x.h"
#include "DCommon.h"
#include "D3DCache.h"
#include "D3D_Main.h"
#include "PCache.h"
#include "D3d_FX.h"
#include "TPage.h"

Go to the source code of this file.

Defines

#define MAX_TEXTURE_HANDLES   32000
#define TEXTURE_CACHE_PERCENT   0.75f
#define LMAP_CACHE_PERCENT   0.25f
#define TSTAGE_0   0
#define TSTAGE_1   1
#define DebugIf(a, b)   if (a) b

Functions

void FreeAllCaches (void)
geRDriver_THandleFindTextureHandle (void)
geBoolean FreeAllTextureHandles (void)
geBoolean THandle_Startup (void)
void THandle_Shutdown (void)
geRDriver_THandleCreate3DTHandle (geRDriver_THandle *THandle, int32 Width, int32 Height, int32 NumMipLevels, const geRDriver_PixelFormat *PixelFormat)
geRDriver_THandleCreateLightmapTHandle (geRDriver_THandle *THandle, int32 Width, int32 Height, int32 NumMipLevels, const geRDriver_PixelFormat *PixelFormat)
geRDriver_THandleCreate2DTHandle (geRDriver_THandle *THandle, int32 Width, int32 Height, int32 NumMipLevels, const geRDriver_PixelFormat *PixelFormat)
geBoolean SetupCurrent3dDesc (gePixelFormat PixelFormat)
geRDriver_THandle *DRIVERCC THandle_Create (int32 Width, int32 Height, int32 NumMipLevels, const geRDriver_PixelFormat *PixelFormat)
geBoolean DRIVERCC THandle_Destroy (geRDriver_THandle *THandle)
geBoolean DRIVERCC THandle_Lock (geRDriver_THandle *THandle, int32 MipLevel, void **Bits)
geBoolean DRIVERCC THandle_UnLock (geRDriver_THandle *THandle, int32 MipLevel)
geBoolean DRIVERCC THandle_GetInfo (geRDriver_THandle *THandle, int32 MipLevel, geRDriver_THandleInfo *Info)
geBoolean CreateSystemToVideoSurfaces (void)
void DestroySystemToVideoSurfaces (void)
geBoolean THandle_CreateSurfaces (THandle_MipData *Surf, int32 Width, int32 Height, DDSURFACEDESC2 *SurfDesc, geBoolean ColorKey, int32 Stage)
void THandle_DestroySurfaces (THandle_MipData *Surf)
geBoolean THandle_CheckCache (void)

Variables

geRDriver_THandle TextureHandles [MAX_TEXTURE_HANDLES]
DDMemMgrMemMgr
DDMemMgr_PartitionPartition [2]
D3DCacheTextureCache
D3DCacheLMapCache
TPage_MgrTPageMgr
DDSURFACEDESC2 CurrentSurfDesc
THandle_MipData SystemToVideo [MAX_LMAP_LOG_SIZE]
geBoolean CacheNeedsUpdate


Define Documentation

#define DebugIf a,
 )     if (a) b
 

Definition at line 586 of file D3D7xDrv/THandle.cpp.

Referenced by THandle_GetInfo().

#define LMAP_CACHE_PERCENT   0.25f
 

Definition at line 57 of file D3D7xDrv/THandle.cpp.

#define MAX_TEXTURE_HANDLES   32000
 

Definition at line 54 of file D3D7xDrv/THandle.cpp.

Referenced by FindTextureHandle(), FreeAllTextureHandles(), GTHandle_CheckTextures(), GTHandle_FindTextureHandle(), GTHandle_FreeAllTextureHandles(), SWTHandle_FindTextureHandle(), SWTHandle_FreeAllTextureHandles(), and THandle_CheckCache().

#define TEXTURE_CACHE_PERCENT   0.75f
 

Definition at line 56 of file D3D7xDrv/THandle.cpp.

Referenced by GTHandle_Startup(), and THandle_Startup().

#define TSTAGE_0   0
 

Definition at line 59 of file D3D7xDrv/THandle.cpp.

#define TSTAGE_1   1
 

Definition at line 60 of file D3D7xDrv/THandle.cpp.


Function Documentation

geRDriver_THandle* Create2DTHandle geRDriver_THandle THandle,
int32  Width,
int32  Height,
int32  NumMipLevels,
const geRDriver_PixelFormat PixelFormat
 

Definition at line 376 of file D3D7xDrv/THandle.cpp.

00377 {
00378         assert(NumMipLevels < THANDLE_MAX_MIP_LEVELS);
00379         assert(NumMipLevels == 1);
00380 
00381         // Save some info about the lightmap
00382         THandle->Width = Width;
00383         THandle->Height = Height;
00384         THandle->NumMipLevels = (uint8)NumMipLevels;
00385         THandle->Log = (uint8)GetLog(Width, Height);
00386         THandle->Stride = Width;
00387 
00388         // Create the surfaces to hold all the mips
00389         THandle->MipData = (THandle_MipData*)malloc(sizeof(THandle_MipData)*NumMipLevels);
00390         memset(THandle->MipData, 0, sizeof(THandle_MipData)*NumMipLevels);
00391         
00392         if (!THandle->MipData)
00393         {
00394                 THandle_Destroy(THandle);
00395                 return NULL;
00396         }
00397         
00398         if (!THandle_CreateSurfaces(&THandle->MipData[0], Width, Height, &CurrentSurfDesc, GE_TRUE, 0))
00399         {
00400                 THandle_Destroy(THandle);
00401                 return NULL;
00402         }
00403 
00404         return THandle;
00405 }

geRDriver_THandle* Create3DTHandle geRDriver_THandle THandle,
int32  Width,
int32  Height,
int32  NumMipLevels,
const geRDriver_PixelFormat PixelFormat
 

Definition at line 241 of file D3D7xDrv/THandle.cpp.

00242 {
00243         int32                           Size, i;
00244 
00245         assert(NumMipLevels < THANDLE_MAX_MIP_LEVELS);
00246         assert(NumMipLevels <= 4);
00247 
00248         // Store width/height info
00249         THandle->Width = Width;
00250         THandle->Height = Height;
00251         THandle->NumMipLevels = (uint8)NumMipLevels;
00252         THandle->Log = (uint8)GetLog(Width, Height);
00253         THandle->Stride = (1<<THandle->Log);
00254 
00255         // Create the surfaces to hold all the mips
00256         THandle->MipData = (THandle_MipData*)malloc(sizeof(THandle_MipData)*NumMipLevels);
00257         memset(THandle->MipData, 0, sizeof(THandle_MipData)*NumMipLevels);
00258         
00259         if (!THandle->MipData)
00260         {
00261                 THandle_Destroy(THandle);
00262                 return NULL;
00263         }
00264 
00265         Size = 1<<THandle->Log;
00266 
00267         // Create all the surfaces for each mip level
00268         for (i=0; i< NumMipLevels; i++)
00269         {
00270                 int32   Stage;
00271 
00272                 if (!THandle_CreateSurfaces(&THandle->MipData[i], Size, Size, &CurrentSurfDesc, GE_FALSE, 0))
00273                 {
00274                         THandle_Destroy(THandle);
00275                         return NULL;
00276                 }
00277 
00278                 // get a cache type for this surface since it is a 3d surface, and will need to be cached on the video card
00279                 //THandle->MipData[i].CacheType = D3DCache_TypeCreate(TextureCache, Size, Size, NumMipLevels, &CurrentSurfDesc);
00280                 // We can use 1 miplevel for the type, since we are createing types for each miplevel...
00281                 if (AppInfo.CanDoMultiTexture)
00282                         Stage = TSTAGE_0;
00283                 else
00284                         Stage = 0;
00285 
00286                 THandle->MipData[i].CacheType = D3DCache_TypeCreate(TextureCache, Size, Size, 1, Stage, &CurrentSurfDesc);
00287 
00288                 if (!THandle->MipData[i].CacheType)
00289                 {
00290                         THandle_Destroy(THandle);
00291                         return NULL;
00292                 }
00293 
00294                 Size>>=1;
00295         }
00296 
00297         return THandle;
00298 }

geRDriver_THandle* CreateLightmapTHandle geRDriver_THandle THandle,
int32  Width,
int32  Height,
int32  NumMipLevels,
const geRDriver_PixelFormat PixelFormat
 

Definition at line 303 of file D3D7xDrv/THandle.cpp.

00304 {
00305         int32                           Size, Stage;
00306 
00307         assert(NumMipLevels < THANDLE_MAX_MIP_LEVELS);
00308 
00309         assert(NumMipLevels == 1);
00310         
00311         // Save some info about the lightmap
00312         THandle->Width = Width;
00313         THandle->Height = Height;
00314         THandle->NumMipLevels = (uint8)NumMipLevels;
00315         THandle->Log = (uint8)GetLog(Width, Height);
00316         THandle->Stride = 1<<THandle->Log;
00317 
00318         assert(THandle->Log < MAX_LMAP_LOG_SIZE);
00319 
00320         Size = 1<<THandle->Log;
00321 
00322         THandle->MipData = (THandle_MipData*)malloc(sizeof(THandle_MipData)*NumMipLevels);
00323         memset(THandle->MipData, 0, sizeof(THandle_MipData)*NumMipLevels);
00324 
00325         THandle->MipData[0].Flags = THANDLE_UPDATE;
00326 
00327 #ifdef D3D_MANAGE_TEXTURES
00328         #ifndef USE_TPAGES
00329         {
00330                 int32           Stage;
00331 
00332                 if (AppInfo.CanDoMultiTexture)
00333                         Stage = STAGE_1;
00334                 else
00335                         Stage = 0;
00336 
00337                 if (!THandle_CreateSurfaces(&THandle->MipData[0], Size, Size, &CurrentSurfDesc, GE_FALSE, Stage))
00338                 {
00339                         THandle_Destroy(THandle);
00340                         return NULL;
00341                 }
00342 
00343 /*   02/25/2001 Wendell Buckner
00344 /*    This texture pointer is no longer valid under directx 7.  Set it to TRUE so there is
00345 /*    something there when  the code does assert checks.        
00346                 D3DSetTexture(0, THandle->MipData[0].Texture); */
00347                 D3DSetTexture(0, THandle->MipData[0].Surface);          
00348 
00349         }
00350         #endif
00351 #endif
00352 
00353         if (AppInfo.CanDoMultiTexture)
00354                 Stage = TSTAGE_1;
00355         else
00356                 Stage = 0;
00357 
00358 #ifdef USE_ONE_CACHE
00359         THandle->MipData[0].CacheType = D3DCache_TypeCreate(TextureCache, Size, Size, NumMipLevels, Stage, &CurrentSurfDesc);
00360 #else
00361         THandle->MipData[0].CacheType = D3DCache_TypeCreate(LMapCache, Size, Size, NumMipLevels, Stage, &CurrentSurfDesc);
00362 #endif
00363 
00364         if (!THandle->MipData[0].CacheType)
00365         {
00366                 THandle_Destroy(THandle);
00367                 return NULL;
00368         }
00369 
00370         return THandle;
00371 }

geBoolean CreateSystemToVideoSurfaces void   ) 
 

Definition at line 622 of file D3D7xDrv/THandle.cpp.

Referenced by THandle_Startup().

00623 {
00624         int32                           i;
00625         DDSURFACEDESC2          SurfDesc;
00626 
00627         memcpy(&SurfDesc, &AppInfo.ddTexFormat, sizeof(DDSURFACEDESC2));
00628 
00629         for (i=0; i<MAX_LMAP_LOG_SIZE; i++)
00630         {
00631                 int32           Size;
00632 
00633                 Size = 1<<i;
00634                 
00635                 if (!THandle_CreateSurfaces(&SystemToVideo[i], Size, Size, &SurfDesc, GE_FALSE, 1))
00636                 {
00637                         DestroySystemToVideoSurfaces();
00638                         return GE_FALSE;
00639                 }
00640         }
00641 
00642         return GE_TRUE;
00643 }

void DestroySystemToVideoSurfaces void   ) 
 

Definition at line 648 of file D3D7xDrv/THandle.cpp.

Referenced by CreateSystemToVideoSurfaces(), and THandle_Shutdown().

00649 {
00650         int32                           i;
00651 
00652         for (i=0; i<MAX_LMAP_LOG_SIZE; i++)
00653                 THandle_DestroySurfaces(&SystemToVideo[i]);
00654 }

geRDriver_THandle* FindTextureHandle void   ) 
 

Definition at line 128 of file D3D7xDrv/THandle.cpp.

Referenced by CreateTexture(), and THandle_Create().

00129 {
00130         int32                           i;
00131         geRDriver_THandle       *pHandle;
00132 
00133         pHandle = TextureHandles;
00134 
00135         for (i=0; i< MAX_TEXTURE_HANDLES; i++, pHandle++)
00136         {
00137                 if (!pHandle->Active)
00138                 {
00139                         memset(pHandle, 0, sizeof(geRDriver_THandle));
00140                         pHandle->Active = 1;
00141                         return pHandle;
00142                 }
00143         }
00144 
00145         SetLastDrvError(DRV_ERROR_GENERIC, "D3D_FindTextureHandle:  No more handles left.\n");
00146 
00147         return NULL;
00148 }

void FreeAllCaches void   ) 
 

Definition at line 93 of file D3D7xDrv/THandle.cpp.

Referenced by THandle_Shutdown().

00094 {
00095         if (LMapCache)
00096                 D3DCache_Destroy(LMapCache);
00097 
00098         if (TextureCache)
00099                 D3DCache_Destroy(TextureCache);
00100 
00101         LMapCache = NULL;
00102         TextureCache = NULL;
00103 
00104         if (Partition[1])
00105                 DDMemMgr_PartitionDestroy(Partition[1]);
00106         if (Partition[0])
00107                 DDMemMgr_PartitionDestroy(Partition[0]);
00108         if (MemMgr)
00109                 DDMemMgr_Destroy(MemMgr);
00110 
00111         
00112 #ifdef USE_TPAGES
00113         if (TPageMgr)
00114         {
00115                 TPage_MgrDestroy(&TPageMgr);
00116                 TPageMgr = NULL;
00117         }
00118 #endif
00119 
00120         Partition[1] = NULL;
00121         Partition[0] = NULL;
00122         MemMgr = NULL;
00123 }

geBoolean FreeAllTextureHandles void   ) 
 

Definition at line 153 of file D3D7xDrv/THandle.cpp.

Referenced by DrvResetAll(), and THandle_Shutdown().

00154 {
00155         int32                           i;
00156         geRDriver_THandle       *pHandle;
00157 
00158         pHandle = TextureHandles;
00159 
00160         for (i=0; i< MAX_TEXTURE_HANDLES; i++, pHandle++)
00161         {
00162                 if (!pHandle->Active)
00163                         continue;
00164 
00165                 if (!THandle_Destroy(pHandle))
00166                         return GE_FALSE;
00167         }
00168 
00169         return GE_TRUE;
00170 }

geBoolean SetupCurrent3dDesc gePixelFormat  PixelFormat  ) 
 

Definition at line 410 of file D3D7xDrv/THandle.cpp.

References AppInfo, CurrentSurfDesc, App_Info::ddFourBitAlphaSurfFormat, App_Info::ddOneBitAlphaSurfFormat, App_Info::ddTexFormat, DRV_ERROR_GENERIC, GE_FALSE, GE_PIXELFORMAT_16BIT_1555_ARGB, GE_PIXELFORMAT_16BIT_4444_ARGB, GE_PIXELFORMAT_16BIT_555_RGB, GE_PIXELFORMAT_16BIT_565_RGB, GE_TRUE, geBoolean, PixelFormat, and SetLastDrvError().

00411 {
00412         switch (PixelFormat)
00413         {
00414                 case GE_PIXELFORMAT_16BIT_555_RGB:
00415                 case GE_PIXELFORMAT_16BIT_565_RGB:
00416                 {
00417                         memcpy(&CurrentSurfDesc, &AppInfo.ddTexFormat, sizeof(DDSURFACEDESC2));
00418                         break;
00419                 }
00420                 case GE_PIXELFORMAT_16BIT_4444_ARGB:
00421                 {
00422                         memcpy(&CurrentSurfDesc, &AppInfo.ddFourBitAlphaSurfFormat, sizeof(DDSURFACEDESC2));
00423                         break;
00424                 }
00425                 case GE_PIXELFORMAT_16BIT_1555_ARGB:
00426                 {
00427                         memcpy(&CurrentSurfDesc, &AppInfo.ddOneBitAlphaSurfFormat, sizeof(DDSURFACEDESC2));
00428                         break;
00429                 }
00430 
00431                 default:
00432                 {
00433                         SetLastDrvError(DRV_ERROR_GENERIC, "SetupCurrent3dDesc:  Invalid pixel format.\n");
00434                         return GE_FALSE;
00435                 }
00436         }
00437 
00438         return GE_TRUE;
00439 }

geBoolean THandle_CheckCache void   ) 
 

Definition at line 764 of file D3D7xDrv/THandle.cpp.

Referenced by BeginScene(), PCache_FlushMiscPolys(), and PCache_FlushWorldPolys().

00765 {
00766         geRDriver_THandle       *pTHandle;
00767         int32                           i, Stage0, Stage1;
00768         int32                           MaxTable1[9], MaxTable2[9];
00769 
00770         if (!CacheNeedsUpdate)
00771                 return GE_TRUE;
00772 
00773 #ifndef D3D_MANAGE_TEXTURES             // If D3D is managing textures, then we don't ned to do any of this...
00774         D3DMain_Log("THandle_CheckCache:  Resetting texture cache...\n");
00775 
00776 #ifdef USE_ONE_CACHE
00777                 #pragma message ("There numbers ARE NOT DONE.  So if USE_ONE_CACHE is defined, please finish this...")
00778                 // Texture cache & Lightmap cache (we are only using one cache, so the combine into the TextureCache)
00779                 MaxTable1[0] = 256;                     //  1x1
00780                 MaxTable1[1] = 256;                     //  2x2
00781                 MaxTable1[2] = 256;                     //  4x4
00782                 MaxTable1[3] = 512;                     //  8x8
00783                 MaxTable1[4] = 512;                     // 16x16
00784                 MaxTable1[5] = 512;                     // 32x32
00785                 MaxTable1[6] = 512;                     // 64x64
00786                 MaxTable1[7] = 256;                     //128x128
00787                 MaxTable1[8] = 256;                     //256x256
00788 #else
00789         if (AppInfo.DeviceIdentifier.dwVendorId == 4634)                // 3dfx series have a limit on the number of texture handles
00790         {
00791                 D3DMain_Log("   3dfx card detected, using smaller number of handles...\n");
00792 
00793                 // Texture cache
00794                 MaxTable1[0] = 24;                      //  1x1
00795                 MaxTable1[1] = 24;                      //  2x2
00796                 MaxTable1[2] = 24;                      //  4x4
00797                 MaxTable1[3] = 24;                      //  8x8
00798                 MaxTable1[4] = 24;                      // 16x16
00799                 MaxTable1[5] = 128;                     // 32x32
00800                 MaxTable1[6] = 128;                     // 64x64
00801                 MaxTable1[7] = 128;                     //128x128
00802                 MaxTable1[8] = 128;                     //256x256
00803 
00804                 // Lightmap cache
00805                 MaxTable2[0] = 128;                     //  1x1
00806                 MaxTable2[1] = 128;                     //  2x2
00807                 MaxTable2[2] = 256;                     //  4x4
00808                 MaxTable2[3] = 256;                     //  8x8
00809                 MaxTable2[4] = 256;                     // 16x16
00810                 MaxTable2[5] = 128;                     // 32x32
00811                 MaxTable2[6] = 128;                     // 64x64
00812                 MaxTable2[7] = 128;                     //128x128
00813                 MaxTable2[8] = 128;                     //256x256
00814         }
00815         else
00816         {
00817                 D3DMain_Log("   NO 3dfx card detected, using larger number of handles...\n");
00818 
00819                 // Texture cache
00820                 MaxTable1[0] = 32;                      //  1x1
00821                 MaxTable1[1] = 32;                      //  2x2
00822                 MaxTable1[2] = 32;                      //  4x4
00823                 MaxTable1[3] = 32;                      //  8x8
00824                 MaxTable1[4] = 32;                      // 16x16
00825                 MaxTable1[5] = 32;                      // 32x32
00826                 MaxTable1[6] = 128;                     // 64x64
00827                 MaxTable1[7] = 128;                     //128x128
00828                 MaxTable1[8] = 128;                     //256x256
00829 
00830                 MaxTable2[0] = 128;                     //  1x1
00831                 MaxTable2[1] = 128;                     //  2x2
00832                 MaxTable2[2] = 256;                     //  4x4
00833                 MaxTable2[3] = 1024;            //  8x8
00834                 MaxTable2[4] = 1024;            // 16x16
00835                 MaxTable2[5] = 512;                     // 32x32
00836                 MaxTable2[6] = 256;                     // 64x64
00837                 MaxTable2[7] = 256;                     //128x128
00838                 MaxTable2[8] = 256;                     //256x256
00839         }
00840 #endif
00841 
00842         if (AppInfo.CanDoMultiTexture)
00843         {
00844                 Stage0 = TSTAGE_0;
00845                 Stage1 = TSTAGE_1;
00846         }
00847         else
00848         {
00849                 Stage0 = 0;                                                        
00850                 Stage1 = 0;
00851         }
00852 
00853         #ifndef USE_ONE_CACHE
00854                 if (!D3DCache_AdjustSlots(LMapCache, MaxTable2, GE_TRUE))
00855                 {
00856                         D3DMain_Log("THandle_CheckCache:  D3DCache_AdjustSlots failed for LMapCache.\n");
00857                         return GE_FALSE;
00858                 }
00859         #endif
00860 
00861         if (!D3DCache_AdjustSlots(TextureCache, MaxTable1, GE_FALSE))
00862         {
00863                 D3DMain_Log("THandle_CheckCache:  D3DCache_AdjustSlots failed for TextureCache.\n");
00864                 return GE_FALSE;
00865         }
00866 
00867 #endif
00868 
00869         // Make sure no THandles reference any slots, because they mave have been moved around, or gotten destroyed...
00870         //  (Evict all textures in the cache)
00871         pTHandle = TextureHandles;
00872 
00873         for (i=0; i< MAX_TEXTURE_HANDLES; i++, pTHandle++)
00874         {
00875                 int32           m;
00876 
00877                 for (m=0; m< pTHandle->NumMipLevels; m++)
00878                 {
00879                         pTHandle->MipData[m].Slot = NULL;
00880                 }
00881         }
00882 
00883         CacheNeedsUpdate = GE_FALSE;
00884 
00885         return GE_TRUE;
00886 }

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

Definition at line 443 of file D3D7xDrv/THandle.cpp.

00444 {
00445         geRDriver_THandle       *THandle;
00446 
00447         THandle = FindTextureHandle();
00448 
00449         if (!THandle)
00450         {
00451                 SetLastDrvError(DRV_ERROR_GENERIC, "D3DDRV:THandle_Create:  Out of texture handles.\n");
00452                 return NULL;
00453         }
00454 
00455         THandle->PixelFormat = *PixelFormat;
00456 
00457         if (PixelFormat->Flags & RDRIVER_PF_3D)
00458         {
00459                 // Get the pixel format desc for this thandle
00460                 if (!SetupCurrent3dDesc(PixelFormat->PixelFormat))
00461                         return NULL;
00462 
00463                 if (!Create3DTHandle(THandle, Width, Height, NumMipLevels, PixelFormat))
00464                         return NULL;
00465 
00466                 CacheNeedsUpdate = GE_TRUE;
00467         }
00468         else if (PixelFormat->Flags & RDRIVER_PF_LIGHTMAP)
00469         {
00470                 // Get the pixel format desc for this thandle
00471                 if (!SetupCurrent3dDesc(PixelFormat->PixelFormat))
00472                         return NULL;
00473 
00474                 if (!CreateLightmapTHandle(THandle, Width, Height, NumMipLevels, PixelFormat))
00475                         return NULL;
00476 
00477                 CacheNeedsUpdate = GE_TRUE;
00478         }
00479         else if (PixelFormat->Flags & RDRIVER_PF_2D)
00480         {
00481                 // 2d surfaces are always this format for now
00482                 memcpy(&CurrentSurfDesc, &AppInfo.ddSurfFormat, sizeof(DDSURFACEDESC2));
00483 
00484                 if (!Create2DTHandle(THandle, Width, Height, NumMipLevels, PixelFormat))
00485                         return NULL;
00486         }
00487 
00488         return THandle;
00489 }

geBoolean THandle_CreateSurfaces THandle_MipData Surf,
int32  Width,
int32  Height,
DDSURFACEDESC2 *  SurfDesc,
geBoolean  ColorKey,
int32  Stage
 

Definition at line 659 of file D3D7xDrv/THandle.cpp.

00660 {
00661 /* 02/25/2001 Wendell Buckner
00662    This texture pointer is no longer valid under directx 7.  Set it to TRUE so there is
00663         LPDIRECTDRAWSURFACE4 Surface;*/
00664         LPDIRECTDRAWSURFACE7 Surface;
00665 
00666         DDSURFACEDESC2          ddsd;
00667         HRESULT                         Hr;
00668                         
00669         memcpy(&ddsd, SurfDesc, sizeof(DDSURFACEDESC2));
00670 
00671         ddsd.dwSize = sizeof(DDSURFACEDESC2);
00672         ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_TEXTURESTAGE;
00673 
00674 #ifdef D3D_MANAGE_TEXTURES
00675         ColorKey = GE_TRUE;                     // Force a colorkey on system surfaces since we are letting D3D do our cacheing...
00676 
00677         ddsd.ddsCaps.dwCaps = 0;
00678         ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC;
00679 #else
00680         ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
00681         ddsd.ddsCaps.dwCaps2 = 0;//DDSCAPS2_HINTDYNAMIC;
00682 #endif
00683 
00684         ddsd.ddsCaps.dwCaps |= DDSCAPS_TEXTURE;
00685         ddsd.ddsCaps.dwCaps2 |= DDSCAPS2_HINTDYNAMIC;
00686 
00687         ddsd.ddsCaps.dwCaps3 = 0;
00688         ddsd.ddsCaps.dwCaps4 = 0;
00689         ddsd.dwWidth = Width;
00690         ddsd.dwHeight = Height;
00691 
00692         ddsd.dwTextureStage = Stage;
00693                         
00694         Hr = AppInfo.lpDD->CreateSurface(&ddsd, &Surface, NULL);
00695 
00696         if(Hr != DD_OK) 
00697         { 
00698                 return FALSE;
00699         }
00700 
00701         Surf->Surface = Surface;
00702         
00703 /* 02/25/2001 Wendell Buckner
00704    This texture pointer is no longer valid under directx 7.  Set it to TRUE so there is
00705    something there when  the code does assert checks.
00706         Surf->Texture = NULL; */
00707     Surf->Texture = Surface;
00708 
00709 /* 02/25/2001 Wendell Buckner
00710    This texture pointer is no longer valid under directx 7.  Set it to TRUE so there is
00711    something there when  the code does assert checks.
00712         Hr = Surface->QueryInterface(IID_IDirect3DTexture2, (void**)&Surf->Texture);  
00713 
00714         if(Hr != DD_OK) 
00715         { 
00716                 Surface->Release();
00717                 return GE_FALSE;
00718         }*/
00719 
00720         if (ColorKey)
00721         {
00722                 DDCOLORKEY                      CKey;
00723                 
00724                 // Create the color key for this surface
00725                 CKey.dwColorSpaceLowValue = 1;
00726                 CKey.dwColorSpaceHighValue = 1;
00727                 
00728                 if (Surf->Surface->SetColorKey(DDCKEY_SRCBLT , &CKey) != DD_OK)
00729                 {
00730                         SetLastDrvError(DRV_ERROR_GENERIC, "THandle_CreateSurfaces: SetColorKey failed for texture.");
00731                         Surf->Surface->Release();
00732                         Surf->Surface = NULL;
00733 
00734 /*   02/25/2001 Wendell Buckner
00735       This texture pointer is no longer valid under directx 7.  Set it to TRUE so there is
00736                         Surf->Texture->Release();*/
00737                         Surf->Texture = NULL;
00738                         
00739                         return FALSE;
00740                 }
00741         }
00742         return GE_TRUE;         // All good dude
00743 }

geBoolean DRIVERCC THandle_Destroy geRDriver_THandle THandle  ) 
 

Definition at line 494 of file D3D7xDrv/THandle.cpp.

00495 {
00496         int32           i;
00497 
00498         assert(THandle);
00499         assert(THandle->Active);
00500 
00501         for (i=0; i< THandle->NumMipLevels; i++)
00502         {
00503                 assert(THandle->MipData);
00504 
00505                 if (THandle->MipData[i].CacheType)
00506                 {
00507                         D3DCache_TypeDestroy(THandle->MipData[i].CacheType);
00508                         CacheNeedsUpdate = GE_TRUE;
00509                         THandle->MipData[i].CacheType = NULL;
00510                 }
00511                 
00512                 if (THandle->MipData[i].Surface)
00513                 {
00514                         assert(THandle->MipData[i].Texture);
00515 
00516                         THandle_DestroySurfaces(&THandle->MipData[i]);
00517                         THandle->MipData[i].Surface = NULL;
00518                         THandle->MipData[i].Texture = NULL;
00519                 }
00520         }
00521 
00522         if (THandle->MipData)
00523                 free(THandle->MipData);
00524 
00525         memset(THandle, 0, sizeof(geRDriver_THandle));
00526 
00527         return GE_TRUE;
00528 }

void THandle_DestroySurfaces THandle_MipData Surf  ) 
 

Definition at line 748 of file D3D7xDrv/THandle.cpp.

00749 {
00750 /*   02/25/2001 Wendell Buckner
00751       This texture pointer is no longer valid under directx 7.  Set it to TRUE so there is
00752         if (Surf->Texture)
00753                 Surf->Texture->Release();*/
00754 
00755         if (Surf->Surface)
00756                 Surf->Surface->Release();
00757 
00758         memset(Surf, 0, sizeof (THandle_MipData));
00759 }

geBoolean DRIVERCC THandle_GetInfo geRDriver_THandle THandle,
int32  MipLevel,
geRDriver_THandleInfo Info
 

Definition at line 594 of file D3D7xDrv/THandle.cpp.

00595 {
00596         DebugIf (MipLevel > THandle->Log, return GE_FALSE);
00597 
00598         Info->Width = THandle->Width>>MipLevel;
00599         Info->Height = THandle->Height>>MipLevel;
00600         Info->Stride = THandle->Stride>>MipLevel;
00601 
00602         if (THandle->PixelFormat.Flags & RDRIVER_PF_CAN_DO_COLORKEY)
00603         {
00604                 Info->Flags = RDRIVER_THANDLE_HAS_COLORKEY;
00605                 Info->ColorKey = 1;
00606         }
00607         else
00608         {
00609                 Info->Flags = 0;
00610                 Info->ColorKey = 0;
00611         }
00612 
00613         Info->PixelFormat = THandle->PixelFormat;
00614 
00615         return GE_TRUE;
00616 }

geBoolean DRIVERCC THandle_Lock geRDriver_THandle THandle,
int32  MipLevel,
void **  Bits
 

Definition at line 532 of file D3D7xDrv/THandle.cpp.

00533 {
00534     DDSURFACEDESC2              SurfDesc;
00535     HRESULT                             Result;
00536 
00537     assert(!(THandle->MipData[MipLevel].Flags & THANDLE_LOCKED));
00538 
00539         // Lock the surface so it can be filled with the data
00540     memset(&SurfDesc, 0, sizeof(DDSURFACEDESC2));
00541     SurfDesc.dwSize = sizeof(DDSURFACEDESC2);
00542 
00543 /* 03/10/2002 Wendell Buckner
00544     Procedural Textures
00545     if you must lock a texture specify the flags WRITEONLY and DISCARDCONTENTS when 
00546     Result = THandle->MipData[MipLevel].Surface->Lock(NULL, &SurfDesc , DDLOCK_WAIT, NULL);*/
00547     Result = THandle->MipData[MipLevel].Surface->Lock(NULL, &SurfDesc , DDLOCK_WAIT | DDLOCK_WRITEONLY | DDLOCK_DISCARDCONTENTS, NULL);
00548 
00549     if (Result != DD_OK) 
00550         {
00551         return GE_FALSE;
00552     }
00553 
00554         THandle->MipData[MipLevel].Flags |= THANDLE_LOCKED;
00555 
00556         *Bits = (void*)SurfDesc.lpSurface;
00557 
00558         return GE_TRUE;
00559 }

void THandle_Shutdown void   ) 
 

Definition at line 229 of file D3D7xDrv/THandle.cpp.

Referenced by D3DMain_Reset(), D3DMain_ShutdownD3D(), and THandle_Startup().

00230 {
00231         FreeAllTextureHandles();
00232         FreeAllCaches();
00233         DestroySystemToVideoSurfaces();
00234 
00235         CacheNeedsUpdate = GE_FALSE;
00236 }

geBoolean THandle_Startup void   ) 
 

Definition at line 174 of file D3D7xDrv/THandle.cpp.

Referenced by D3DMain_InitD3D(), D3DMain_Reset(), and DrvInit().

00175 {
00176         // Create the main memory manager
00177         MemMgr = DDMemMgr_Create(AppInfo.VidMemFree);
00178 
00179         if (!MemMgr)
00180                 goto ExitWithError;
00181 
00182         // Create partition 0
00183         Partition[0] = DDMemMgr_PartitionCreate(MemMgr, (uint32)((float)DDMemMgr_GetFreeMem(MemMgr)*TEXTURE_CACHE_PERCENT));
00184 
00185         if (!Partition[0])
00186                 goto ExitWithError;
00187 
00188         // Create partition 1
00189         Partition[1] = DDMemMgr_PartitionCreate(MemMgr, DDMemMgr_GetFreeMem(MemMgr));
00190 
00191         if (!Partition[1])
00192                 goto ExitWithError;
00193 
00194         // Create the texture cache from partition 0
00195         TextureCache = D3DCache_Create("Main Texture Cache", AppInfo.lpDD, Partition[0], AppInfo.CanDoMultiTexture);
00196 
00197         if (!TextureCache)
00198                 goto ExitWithError;
00199 
00200 #ifndef USE_ONE_CACHE
00201         // Create the lmap cache from partition 1
00202         LMapCache = D3DCache_Create("Lightmap Cache", AppInfo.lpDD, Partition[1], AppInfo.CanDoMultiTexture);
00203 
00204         if (!LMapCache)
00205                 goto ExitWithError;
00206 #endif
00207 
00208         // Create all the system to video surfaces (for lmaps)
00209         if (!CreateSystemToVideoSurfaces())
00210                 goto ExitWithError;
00211 
00212         #ifdef USE_TPAGES
00213                 TPageMgr = TPage_MgrCreate(AppInfo.lpDD, &AppInfo.ddTexFormat, 512);
00214                 if (!TPageMgr)
00215                         goto ExitWithError;
00216         #endif
00217 
00218         return GE_TRUE;
00219 
00220         ExitWithError:
00221         {
00222                 THandle_Shutdown();
00223                 return GE_FALSE;
00224         }
00225 }

geBoolean DRIVERCC THandle_UnLock geRDriver_THandle THandle,
int32  MipLevel
 

Definition at line 564 of file D3D7xDrv/THandle.cpp.

00565 {
00566     HRESULT                             Result;
00567 
00568     assert(MipLevel <= THandle->NumMipLevels);
00569     assert(THandle->MipData[MipLevel].Flags & THANDLE_LOCKED);
00570 
00571         // Unlock the surface
00572     Result = THandle->MipData[MipLevel].Surface->Unlock(NULL);
00573 
00574     if (Result != DD_OK) 
00575         {
00576         return GE_FALSE;
00577     }
00578 
00579         THandle->MipData[MipLevel].Flags |= THANDLE_UPDATE;
00580         THandle->MipData[MipLevel].Flags &= ~THANDLE_LOCKED;
00581 
00582         return GE_TRUE;
00583 }


Variable Documentation

geBoolean CacheNeedsUpdate
 

Definition at line 79 of file D3D7xDrv/THandle.cpp.

Referenced by THandle_CheckCache(), THandle_Create(), THandle_Destroy(), and THandle_Shutdown().

DDSURFACEDESC2 CurrentSurfDesc
 

Definition at line 75 of file D3D7xDrv/THandle.cpp.

Referenced by Create2DTHandle(), Create3DTHandle(), CreateLightmapTHandle(), SetupCurrent3dDesc(), and THandle_Create().

D3DCache* LMapCache
 

Definition at line 71 of file D3D7xDrv/THandle.cpp.

Referenced by CreateLightmapTexture(), CreateLightmapTHandle(), D3DMain_RestoreAllSurfaces(), DownloadLightmap(), FreeAllCaches(), GTHandle_CheckTextures(), GTHandle_FreeAllCaches(), GTHandle_Startup(), THandle_CheckCache(), and THandle_Startup().

DDMemMgr* MemMgr
 

Definition at line 67 of file D3D7xDrv/THandle.cpp.

Referenced by DDMemMgr_Create(), DDMemMgr_Destroy(), DDMemMgr_GetFreeMem(), DDMemMgr_PartitionCreate(), DDMemMgr_Reset(), FreeAllCaches(), GCache_Create(), GMemMgr_AllocMem(), GMemMgr_Create(), GMemMgr_Destroy(), GMemMgr_GetFreeMemory(), GMemMgr_GetTmu(), GMemMgr_GetTotalMemory(), GMemMgr_Reset(), GTHandle_FreeAllCaches(), GTHandle_Startup(), and THandle_Startup().

DDMemMgr_Partition* Partition[2]
 

Definition at line 68 of file D3D7xDrv/THandle.cpp.

Referenced by D3DCache_Create(), DDMemMgr_PartitionAllocMem(), DDMemMgr_PartitionDestroy(), DDMemMgr_PartitionGetFreeMem(), DDMemMgr_PartitionGetTotalMem(), DDMemMgr_PartitionReset(), FreeAllCaches(), and THandle_Startup().

THandle_MipData SystemToVideo[MAX_LMAP_LOG_SIZE]
 

Definition at line 77 of file D3D7xDrv/THandle.cpp.

Referenced by CreateSystemToVideoSurfaces(), DestroySystemToVideoSurfaces(), LoadLMapFromSystem(), and SetupLMap().

D3DCache* TextureCache
 

Definition at line 70 of file D3D7xDrv/THandle.cpp.

Referenced by Create3DTexture(), Create3DTHandle(), CreateLightmapTHandle(), D3DMain_RestoreAllSurfaces(), FreeAllCaches(), GTHandle_CheckTextures(), GTHandle_FreeAllCaches(), GTHandle_Startup(), SetupTexture(), THandle_CheckCache(), and THandle_Startup().

geRDriver_THandle TextureHandles
 

Definition at line 65 of file D3D7xDrv/THandle.cpp.

Referenced by FindTextureHandle(), FreeAllTextureHandles(), GTHandle_CheckTextures(), GTHandle_FindTextureHandle(), GTHandle_FreeAllTextureHandles(), PCache_InsertMiscPoly(), PCache_InsertWorldPoly(), and THandle_CheckCache().

TPage_Mgr* TPageMgr
 

Definition at line 73 of file D3D7xDrv/THandle.cpp.

Referenced by FreeAllCaches(), SetupLMap(), THandle_Startup(), TPage_MgrCreate(), and TPage_MgrDestroy().


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