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

Pcache.cpp File Reference

#include <Windows.h>
#include <stdio.h>
#include "D3DCache.h"
#include "D3D_Fx.h"
#include "PCache.h"
#include "D3DDrv.h"
#include "THandle.h"
#include "D3D_Err.h"
#include <Math.h>

Go to the source code of this file.

Compounds

struct  Misc_Cache
struct  Misc_Poly
struct  PCache_TVert
struct  PCache_UVSet
struct  PCache_Vert
struct  World_Cache
struct  World_Poly

Defines

#define MAX_WORLD_POLYS   256
#define MAX_WORLD_POLY_VERTS   1024
#define MAX_MISC_POLYS   256
#define MAX_MISC_POLY_VERTS   1024
#define MAX_TEXTURE_STAGES   2
#define PREP_WORLD_VERTS_NORMAL   1
#define PREP_WORLD_VERTS_LMAP   2
#define PREP_WORLD_VERTS_SINGLE_PASS   3
#define RENDER_WORLD_POLYS_NORMAL   1
#define RENDER_WORLD_POLYS_LMAP   2
#define RENDER_WORLD_POLYS_SINGLE_PASS   3
#define TSTAGE_0   0
#define TSTAGE_1   1

Functions

geBoolean World_PolyPrepVerts (World_Poly *pPoly, int32 PrepMode, int32 Stage1, int32 Stage2)
BOOL RenderWorldPolys (int32 RenderMode)
BOOL ClearWorldCache (void)
int32 GetMipLevel (DRV_TLVertex *Verts, int32 NumVerts, float ScaleU, float ScaleV, int32 MaxMipLevel)
BOOL PCache_InsertWorldPoly (DRV_TLVertex *Verts, int32 NumVerts, geRDriver_THandle *THandle, DRV_TexInfo *TexInfo, DRV_LInfo *LInfo, uint32 Flags)
BOOL PCache_FlushWorldPolys (void)
int MiscBitmapHandleComp (const void *a, const void *b)
void SortMiscPolysByHandle (void)
void FillLMapSurface (DRV_LInfo *LInfo, int32 LNum)
void LoadLMapFromSystem (DRV_LInfo *LInfo, int32 Log, int32 LNum)
BOOL IsKeyDown (int KeyCode)
geBoolean SetupMipData (THandle_MipData *MipData)
geBoolean SetupLMap (int32 Stage, DRV_LInfo *LInfo, int32 LNum, geBoolean Dynamic)
geBoolean SetupTexture (int32 Stage, geRDriver_THandle *THandle, int32 MipLevel)
BOOL PCache_FlushMiscPolys (void)
BOOL PCache_InsertMiscPoly (DRV_TLVertex *Verts, int32 NumVerts, geRDriver_THandle *THandle, uint32 Flags)
int BitmapHandleComp (const void *a, const void *b)
void SortWorldPolysByHandle (void)
BOOL PCache_Reset (void)

Variables

DRV_CacheInfo CacheInfo
World_Cache WorldCache
Misc_Cache MiscCache
uint32 CurrentLRU
D3DTEXTUREHANDLE OldId
LPDIRECT3DTEXTURE2 OldTexture [8]


Define Documentation

#define MAX_MISC_POLY_VERTS   1024
 

Definition at line 54 of file D3D8Drv/Pcache.cpp.

#define MAX_MISC_POLYS   256
 

Definition at line 53 of file D3D8Drv/Pcache.cpp.

#define MAX_TEXTURE_STAGES   2
 

Definition at line 80 of file D3D8Drv/Pcache.cpp.

#define MAX_WORLD_POLY_VERTS   1024
 

Definition at line 51 of file D3D8Drv/Pcache.cpp.

#define MAX_WORLD_POLYS   256
 

Definition at line 50 of file D3D8Drv/Pcache.cpp.

#define PREP_WORLD_VERTS_LMAP   2
 

Definition at line 115 of file D3D8Drv/Pcache.cpp.

#define PREP_WORLD_VERTS_NORMAL   1
 

Definition at line 114 of file D3D8Drv/Pcache.cpp.

#define PREP_WORLD_VERTS_SINGLE_PASS   3
 

Definition at line 116 of file D3D8Drv/Pcache.cpp.

#define RENDER_WORLD_POLYS_LMAP   2
 

Definition at line 119 of file D3D8Drv/Pcache.cpp.

#define RENDER_WORLD_POLYS_NORMAL   1
 

Definition at line 118 of file D3D8Drv/Pcache.cpp.

#define RENDER_WORLD_POLYS_SINGLE_PASS   3
 

Definition at line 120 of file D3D8Drv/Pcache.cpp.

#define TSTAGE_0   0
 

Definition at line 923 of file D3D8Drv/Pcache.cpp.

#define TSTAGE_1   1
 

Definition at line 924 of file D3D8Drv/Pcache.cpp.


Function Documentation

int BitmapHandleComp const void *  a,
const void *  b
[static]
 

Definition at line 888 of file D3D8Drv/Pcache.cpp.

References int32.

Referenced by SortWorldPolysByHandle().

00889 {
00890         int32   Id1, Id2;
00891 
00892         Id1 = (*(World_Poly**)a)->SortKey;
00893         Id2 = (*(World_Poly**)b)->SortKey;
00894 
00895         if ( Id1 == Id2)
00896                 return 0;
00897 
00898         if (Id1 < Id2)
00899                 return -1;
00900 
00901         return 1;
00902 }

BOOL ClearWorldCache void   )  [static]
 

Definition at line 1190 of file D3D8Drv/Pcache.cpp.

References World_Cache::NumPolys, World_Cache::NumVerts, TRUE, and WorldCache.

01191 {
01192         WorldCache.NumPolys = 0;
01193         WorldCache.NumVerts = 0;
01194 
01195         return TRUE;
01196 }

void FillLMapSurface DRV_LInfo LInfo,
int32  LNum
[static]
 

Definition at line 344 of file D3D8Drv/Pcache.cpp.

References AppInfo, RGB_LUT::B, B, RGB_LUT::G, G, DRV_LInfo::Height, int32, geRDriver_THandle::Log, App_Info::Lut1, RGB_LUT::R, R, DRV_LInfo::RGBLight, DRV_LInfo::THandle, THandle_Lock(), THandle_UnLock(), U16, U8, and DRV_LInfo::Width.

00345 {
00346         U16                                     *pTempBits;
00347         int32                           w, h, Width, Height, Size;
00348         U8                                      *pBitPtr;
00349         RGB_LUT                         *Lut;
00350         geRDriver_THandle       *THandle;
00351         int32                           Extra;
00352 
00353         THandle = LInfo->THandle;
00354 
00355         pBitPtr = (U8*)LInfo->RGBLight[LNum];
00356 
00357         Width = LInfo->Width;
00358         Height = LInfo->Height;
00359         Size = 1<<THandle->Log;
00360 
00361         Lut = &AppInfo.Lut1;
00362 
00363         THandle_Lock(THandle, 0, (void**)&pTempBits);
00364 
00365         Extra = Size - Width;
00366 
00367         for (h=0; h< Height; h++)
00368         {
00369                 for (w=0; w< Width; w++)
00370                 {
00371                         U8      R, G, B;
00372                         U16     Color;
00373                         R = *pBitPtr++;
00374                         G = *pBitPtr++;
00375                         B =  *pBitPtr++;
00376                         
00377                         Color = (U16)(Lut->R[R] | Lut->G[G] | Lut->B[B]);
00378 
00379                         *pTempBits++ = Color;
00380                 }
00381                 pTempBits += Extra;
00382         }
00383 
00384         THandle_UnLock(THandle, 0);
00385 }

int32 GetMipLevel DRV_TLVertex Verts,
int32  NumVerts,
float  ScaleU,
float  ScaleV,
int32  MaxMipLevel
[static]
 

Definition at line 1214 of file D3D8Drv/Pcache.cpp.

References int32, DRV_TLVertex::u, DRV_TLVertex::v, DRV_TLVertex::x, and DRV_TLVertex::y.

01215 {
01216         int32           Mip;
01217 
01218         if (MaxMipLevel == 0)
01219                 return 0;
01220 
01221         //
01222         //      Get the MipLevel
01223         //
01224         {
01225                 float           du, dv, dx, dy, MipScale;
01226 
01227                 int32           i;
01228 
01229                 MipScale = 999999.0f;
01230 
01231                 for (i=0; i< NumVerts; i++)
01232                 {
01233                         float                   MipScaleT;
01234                         DRV_TLVertex    *pVert0, *pVert1;
01235                         int32                   i2;
01236 
01237                         i2 = i+1;
01238 
01239                         if (i2 >= NumVerts)
01240                                 i2=0;
01241 
01242                         pVert0 = &Verts[i];
01243                         pVert1 = &Verts[i2];
01244 
01245                         du = pVert1->u - pVert0->u;
01246                         dv = pVert1->v - pVert0->v;
01247                         dx = pVert1->x - pVert0->x;
01248                         dy = pVert1->y - pVert0->y;
01249                         
01250                         du *= ScaleU;
01251                         dv *= ScaleV;
01252 
01253                         MipScaleT = ((du*du)+(dv*dv)) / ((dx*dx)+(dy*dy));
01254 
01255                         if (MipScaleT < MipScale)
01256                                 MipScale = MipScaleT;           // Record the best MipScale (the one closest to the the eye)
01257                 }
01258 
01259                 if (MipScale <= 4)              // 2, 6, 12
01260                         Mip = 0;
01261                 else if (MipScale <= 15)
01262                         Mip = 1;
01263                 else if (MipScale <= 40)
01264                         Mip = 2;
01265                 else
01266                         Mip = 3;
01267         }
01268 
01269         if (Mip > MaxMipLevel)
01270                 Mip = MaxMipLevel;
01271 
01272         return Mip;
01273 }

BOOL IsKeyDown int  KeyCode  )  [static]
 

Definition at line 439 of file D3D8Drv/Pcache.cpp.

References FALSE, and TRUE.

00440 {
00441         if (GetAsyncKeyState(KeyCode) & 0x8000)
00442                 return TRUE;
00443 
00444         return FALSE;
00445 }

void LoadLMapFromSystem DRV_LInfo LInfo,
int32  Log,
int32  LNum
[static]
 

Definition at line 391 of file D3D8Drv/Pcache.cpp.

References AppInfo, RGB_LUT::B, B, RGB_LUT::G, G, DRV_LInfo::Height, int32, App_Info::Lut1, NULL, RGB_LUT::R, R, DRV_LInfo::RGBLight, THandle_MipData::Surface, SystemToVideo, U16, U8, USHORT, and DRV_LInfo::Width.

00392 {
00393         U16                                     *pTempBits;
00394         int32                           w, h, Width, Height, Size, Extra;
00395         U8                                      *pBitPtr;
00396         LPDIRECTDRAWSURFACE4 Surface;
00397         RGB_LUT                         *Lut;
00398     DDSURFACEDESC2              ddsd;
00399     HRESULT                             ddrval;
00400 
00401         pBitPtr = (U8*)LInfo->RGBLight[LNum];
00402 
00403         Width = LInfo->Width;
00404         Height = LInfo->Height;
00405         Size = 1<<Log;
00406 
00407         Extra = Size - Width;
00408 
00409         Lut = &AppInfo.Lut1;
00410 
00411         Surface = SystemToVideo[Log].Surface;
00412 
00413     memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
00414     ddsd.dwSize = sizeof(DDSURFACEDESC2);
00415     ddrval = Surface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
00416 
00417         pTempBits = (USHORT*)ddsd.lpSurface;
00418 
00419         for (h=0; h< Height; h++)
00420         {
00421                 for (w=0; w< Width; w++)
00422                 {
00423                         U8      R, G, B;
00424                         U16     Color;
00425                         R = *pBitPtr++;
00426                         G = *pBitPtr++;
00427                         B =  *pBitPtr++;
00428                         
00429                         Color = (U16)(Lut->R[R] | Lut->G[G] | Lut->B[B]);
00430                         
00431                         *pTempBits++ = Color;
00432                 }
00433                 pTempBits += Extra;
00434         }
00435 
00436     ddrval = Surface->Unlock(NULL);
00437 }

int MiscBitmapHandleComp const void *  a,
const void *  b
[static]
 

Definition at line 306 of file D3D8Drv/Pcache.cpp.

References uint32.

Referenced by SortMiscPolysByHandle().

00307 {
00308         uint32  Id1, Id2;
00309 
00310         Id1 = (uint32)(*(Misc_Poly**)a)->SortKey;
00311         Id2 = (uint32)(*(Misc_Poly**)b)->SortKey;
00312 
00313         if ( Id1 == Id2)
00314                 return 0;
00315 
00316         if (Id1 < Id2)
00317                 return -1;
00318 
00319         return 1;
00320 }

BOOL PCache_FlushMiscPolys void   ) 
 

Definition at line 575 of file D3D8Drv/Pcache.cpp.

References AppInfo, App_Info::CanDoMultiTexture, D3DBlendEnable(), D3DBlendFunc(), D3DSetTexture(), D3DTexturedPoly(), D3DTexWrap(), D3DZEnable(), D3DZWriteEnable(), DRV_RENDER_CLAMP_UV, DRV_RENDER_NO_ZMASK, DRV_RENDER_NO_ZWRITE, DRV_RENDER_POLY_NO_FOG, FALSE, Misc_Poly::FirstVert, Misc_Poly::Flags, App_Info::FogEnable, GE_FALSE, int32, App_Info::lpD3DDevice, Misc_Poly::MipLevel, MiscCache, NULL, Misc_Cache::NumPolys, Misc_Cache::NumVerts, Misc_Poly::NumVerts, SetupTexture(), Misc_Cache::SortedPolys, SortMiscPolysByHandle(), Misc_Poly::THandle, THandle_CheckCache(), TRUE, and Misc_Cache::Verts.

00576 {
00577         int32                           i;
00578         Misc_Poly                       *pPoly;
00579 
00580         if (!MiscCache.NumPolys)
00581                 return TRUE;
00582 
00583         if (!THandle_CheckCache())
00584                 return GE_FALSE;
00585 
00586         // Set the render states
00587         if (AppInfo.CanDoMultiTexture)
00588         {
00589                 AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
00590                 AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
00591                 D3DSetTexture(1, NULL);         // Reset texture stage 1
00592         }
00593         
00594         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0);
00595 
00596         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
00597         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
00598         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
00599         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
00600         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
00601         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE);
00602 
00603         D3DBlendFunc (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
00604         D3DBlendEnable(TRUE);
00605 
00606         // Sort the polys by handle
00607         SortMiscPolysByHandle();
00608 
00609         for (i=0; i< MiscCache.NumPolys; i++)
00610         {
00611                 pPoly = MiscCache.SortedPolys[i];
00612 
00613                 if (pPoly->Flags & DRV_RENDER_NO_ZMASK)         // We are assuming that this is not going to change all that much
00614                         D3DZEnable(FALSE);
00615                 else
00616                         D3DZEnable(TRUE);
00617 
00618                 if (pPoly->Flags & DRV_RENDER_NO_ZWRITE)        // We are assuming that this is not going to change all that much
00619                         D3DZWriteEnable(FALSE); 
00620                 else
00621                         D3DZWriteEnable(TRUE);
00622                                                                           
00623                 if (pPoly->Flags & DRV_RENDER_CLAMP_UV)
00624                         D3DTexWrap(0, FALSE);
00625                 else
00626                         D3DTexWrap(0, TRUE);
00627 
00628                 if (!SetupTexture(0, pPoly->THandle, pPoly->MipLevel))
00629                         return GE_FALSE;
00630 
00631                 if ( (pPoly->Flags & DRV_RENDER_POLY_NO_FOG) && AppInfo.FogEnable) // poly fog
00632                         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , FALSE);
00633 
00634                 D3DTexturedPoly(&MiscCache.Verts[pPoly->FirstVert], pPoly->NumVerts);
00635 
00636                 if ( (pPoly->Flags & DRV_RENDER_POLY_NO_FOG) && AppInfo.FogEnable) // poly fog
00637                         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , TRUE);
00638         }
00639 
00640         // Turn z stuff back on...
00641         D3DZWriteEnable (TRUE);
00642         D3DZEnable(TRUE);
00643         
00644         MiscCache.NumPolys = 0;
00645         MiscCache.NumVerts = 0;
00646 
00647         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FLUSHBATCH, 0);
00648         AppInfo.lpD3DDevice->EndScene();
00649         AppInfo.lpD3DDevice->BeginScene();
00650 
00651         return TRUE;
00652 }

BOOL PCache_FlushWorldPolys void   ) 
 

Definition at line 277 of file D3D8Drv/Pcache.cpp.

References AppInfo, App_Info::CanDoMultiTexture, ClearWorldCache(), GE_FALSE, World_Cache::NumPolys, RENDER_WORLD_POLYS_LMAP, RENDER_WORLD_POLYS_NORMAL, RENDER_WORLD_POLYS_SINGLE_PASS, RenderWorldPolys(), THandle_CheckCache(), TRUE, and WorldCache.

00278 {
00279         if (!WorldCache.NumPolys)
00280                 return TRUE;
00281 
00282         if (!THandle_CheckCache())
00283                 return GE_FALSE;
00284         
00285         if (AppInfo.CanDoMultiTexture)
00286         {
00287                 RenderWorldPolys(RENDER_WORLD_POLYS_SINGLE_PASS);
00288         }
00289         else
00290         {
00291                 // Render them as normal
00292                 if (!RenderWorldPolys(RENDER_WORLD_POLYS_NORMAL))
00293                         return GE_FALSE;
00294 
00295                 // Render them as lmaps
00296                 RenderWorldPolys(RENDER_WORLD_POLYS_LMAP);
00297         }
00298 
00299         ClearWorldCache();
00300 
00301         return TRUE;
00302 }

BOOL PCache_InsertMiscPoly DRV_TLVertex Verts,
int32  NumVerts,
geRDriver_THandle THandle,
uint32  Flags
 

Definition at line 657 of file D3D8Drv/Pcache.cpp.

References DRV_TLVertex::a, AppInfo, DRV_TLVertex::b, PCache_Vert::color, DRV_RENDER_POLY_NO_FOG, DWORD, Misc_Poly::FirstVert, Misc_Poly::Flags, App_Info::FogEnable, App_Info::FogEnd, App_Info::FogStart, DRV_TLVertex::g, GetMipLevel(), geRDriver_THandle::Height, int32, geRDriver_THandle::Log, MAX_MISC_POLY_VERTS, MAX_MISC_POLYS, Misc_Poly::MipLevel, MiscCache, geRDriver_THandle::NumMipLevels, Misc_Cache::NumPolys, Misc_Poly::NumVerts, Misc_Cache::NumVerts, PCache_FlushMiscPolys(), Misc_Cache::Polys, DRV_TLVertex::r, PCache_Vert::rhw, Misc_Poly::SortKey, PCache_Vert::specular, TextureHandles, Misc_Poly::THandle, TRUE, PCache_UVSet::u, DRV_TLVertex::u, PCache_Vert::uv, PCache_UVSet::v, DRV_TLVertex::v, v, Misc_Cache::Verts, geRDriver_THandle::Width, DRV_TLVertex::x, PCache_Vert::x, DRV_TLVertex::y, PCache_Vert::y, PCache_Vert::z, and DRV_TLVertex::z.

00658 {
00659         int32                   Mip;
00660         float                   ZRecip, u, v, ScaleU, ScaleV, InvScale;
00661         Misc_Poly               *pCachePoly;
00662         DRV_TLVertex    *pVerts;
00663         PCache_Vert             *pD3DVerts;
00664         int32                   i, SAlpha;
00665 
00666         if ((MiscCache.NumVerts + NumVerts) >= MAX_MISC_POLY_VERTS)
00667         {
00668                 // If the cache is full, we must flush it before going on...
00669                 PCache_FlushMiscPolys();
00670         }
00671         else if (MiscCache.NumPolys+1 >= MAX_MISC_POLYS)
00672         {
00673                 // If the cache is full, we must flush it before going on...
00674                 PCache_FlushMiscPolys();
00675         }
00676 
00677         Mip = GetMipLevel(Verts, NumVerts, (float)THandle->Width, (float)THandle->Height, THandle->NumMipLevels-1);
00678 
00679         // Store info about this poly in the cache
00680         pCachePoly = &MiscCache.Polys[MiscCache.NumPolys];
00681 
00682         pCachePoly->THandle = THandle;
00683         pCachePoly->Flags = Flags;
00684         pCachePoly->FirstVert = MiscCache.NumVerts;
00685         pCachePoly->NumVerts = NumVerts;
00686         pCachePoly->MipLevel = Mip;
00687         pCachePoly->SortKey = ((THandle - TextureHandles)<<4)+Mip;
00688 
00689         // Get scale value for vertices
00690         //TCache_GetUVInvScale(Bitmap, Mip, &InvScale);
00691         InvScale = 1.0f / (float)((1<<THandle->Log));
00692 
00693         // Convert them to take account that the vertices are allready from 0 to 1
00694         ScaleU = (float)THandle->Width * InvScale;
00695         ScaleV = (float)THandle->Height * InvScale;
00696 
00697         // Precompute the alpha value...
00698         SAlpha = ((int32)Verts->a)<<24;
00699 
00700         // Get a pointer to the original polys verts
00701         pVerts = Verts;
00702         // Get a pointer into the world verts
00703         pD3DVerts = &MiscCache.Verts[MiscCache.NumVerts];
00704 
00705         for (i=0; i< NumVerts; i++)
00706         {
00707                 ZRecip = 1/(pVerts->z);
00708 
00709                 pD3DVerts->x = pVerts->x;
00710                 pD3DVerts->y = pVerts->y;
00711 
00712                 pD3DVerts->z = (1.0f - ZRecip);         // ZBUFFER
00713                 pD3DVerts->rhw = ZRecip;
00714                 
00715                 u = pVerts->u * ScaleU;
00716                 v = pVerts->v * ScaleV;
00717 
00718                 pD3DVerts->uv[0].u = u;
00719                 pD3DVerts->uv[0].v = v;
00720 
00721                 pD3DVerts->color = SAlpha | ((int32)pVerts->r<<16) | ((int32)pVerts->g<<8) | (int32)pVerts->b;
00722 
00723                 if (AppInfo.FogEnable && !(Flags & DRV_RENDER_POLY_NO_FOG) ) // poly fog
00724                 {
00725                         DWORD   FogVal;
00726                         float   Val;
00727 
00728                         Val = pVerts->z;
00729 
00730                         if (Val > AppInfo.FogEnd)
00731                                 Val = AppInfo.FogEnd;
00732 
00733                         FogVal = (DWORD)((AppInfo.FogEnd-Val)/(AppInfo.FogEnd-AppInfo.FogStart)*255.0f);
00734                 
00735                         if (FogVal < 0)
00736                                 FogVal = 0;
00737                         else if (FogVal > 255)
00738                                 FogVal = 255;
00739                 
00740                         pD3DVerts->specular = (FogVal<<24);             // Alpha component in specular is the fog value (0...255)
00741                 }
00742                 else
00743                         pD3DVerts->specular = 0;
00744 
00745                 pVerts++;
00746                 pD3DVerts++;
00747         }
00748         
00749         // Update globals about the misc poly cache
00750         MiscCache.NumVerts += NumVerts;
00751         MiscCache.NumPolys++;
00752 
00753         return TRUE;
00754 }

BOOL PCache_InsertWorldPoly DRV_TLVertex Verts,
int32  NumVerts,
geRDriver_THandle THandle,
DRV_TexInfo TexInfo,
DRV_LInfo LInfo,
uint32  Flags
 

Definition at line 164 of file D3D8Drv/Pcache.cpp.

References DRV_TLVertex::a, AppInfo, DRV_TLVertex::b, PCache_TVert::Color, DRV_TexInfo::DrawScaleU, DRV_TexInfo::DrawScaleV, DRV_RENDER_ALPHA, DRV_RENDER_POLY_NO_FOG, DWORD, World_Poly::FirstVert, World_Poly::Flags, App_Info::FogEnable, App_Info::FogEnd, App_Info::FogStart, DRV_TLVertex::g, GE_FALSE, GetMipLevel(), int32, World_Poly::LInfo, MAX_WORLD_POLY_VERTS, MAX_WORLD_POLYS, World_Poly::MipLevel, geRDriver_THandle::NumMipLevels, World_Cache::NumPolys, World_Poly::NumVerts, World_Cache::NumVerts, PCache_FlushWorldPolys(), World_Cache::Polys, DRV_TLVertex::r, PCache_Vert::rhw, World_Poly::ScaleU, World_Poly::ScaleV, DRV_TexInfo::ShiftU, World_Poly::ShiftU, DRV_TexInfo::ShiftV, World_Poly::ShiftV, World_Poly::SortKey, PCache_Vert::specular, TextureHandles, World_Poly::THandle, TRUE, World_Cache::TVerts, DRV_TLVertex::u, PCache_TVert::u, uint32, DRV_TLVertex::v, PCache_TVert::v, World_Cache::Verts, WorldCache, DRV_TLVertex::x, PCache_Vert::x, DRV_TLVertex::y, PCache_Vert::y, PCache_Vert::z, and DRV_TLVertex::z.

00165 {
00166         int32                   Mip;
00167         float                   ZRecip, DrawScaleU, DrawScaleV;
00168         World_Poly              *pCachePoly;
00169         DRV_TLVertex    *pVerts;
00170         PCache_TVert    *pTVerts;
00171         PCache_Vert             *pD3DVerts;
00172         int32                   i;
00173         uint32                  Alpha;
00174 
00175 
00176         if ((WorldCache.NumVerts + NumVerts) >= MAX_WORLD_POLY_VERTS)
00177         {
00178                 // If the cache is full, we must flush it before going on...
00179                 if (!PCache_FlushWorldPolys())
00180                         return GE_FALSE;
00181         }
00182         else if (WorldCache.NumPolys+1 >= MAX_WORLD_POLYS)
00183         {
00184                 // If the cache is full, we must flush it before going on...
00185                 if (!PCache_FlushWorldPolys())
00186                         return GE_FALSE;
00187         }
00188 
00189         DrawScaleU = 1.0f / TexInfo->DrawScaleU;
00190         DrawScaleV = 1.0f / TexInfo->DrawScaleV;
00191 
00192         Mip = GetMipLevel(Verts, NumVerts, DrawScaleU, DrawScaleV, THandle->NumMipLevels-1);
00193 
00194         // Get a pointer to the original polys verts
00195         pVerts = Verts;
00196         
00197         // Store info about this poly in the cache
00198         pCachePoly = &WorldCache.Polys[WorldCache.NumPolys];
00199 
00200         pCachePoly->THandle = THandle;
00201         pCachePoly->LInfo = LInfo;
00202         pCachePoly->Flags = Flags;
00203         pCachePoly->FirstVert = WorldCache.NumVerts;
00204         pCachePoly->NumVerts = NumVerts;
00205         pCachePoly->ShiftU = TexInfo->ShiftU;
00206         pCachePoly->ShiftV = TexInfo->ShiftV;
00207         pCachePoly->ScaleU = DrawScaleU;
00208         pCachePoly->ScaleV = DrawScaleV;
00209         pCachePoly->MipLevel = Mip;
00210 
00211         // Don't forget the sort key:
00212         pCachePoly->SortKey = ((THandle - TextureHandles)<<4)+Mip;
00213 
00214         // Get a pointer into the world verts
00215         pD3DVerts = &WorldCache.Verts[WorldCache.NumVerts];
00216         pTVerts = &WorldCache.TVerts[WorldCache.NumVerts];
00217 
00218         if (Flags & DRV_RENDER_ALPHA)
00219                 Alpha = (uint32)pVerts->a<<24;
00220         else
00221                 Alpha = (uint32)(255<<24);
00222 
00223         for (i=0; i< NumVerts; i++)
00224         {
00225                 ZRecip = 1.0f/(pVerts->z);
00226 
00227                 pD3DVerts->x = pVerts->x;
00228                 pD3DVerts->y = pVerts->y;
00229 
00230                 pD3DVerts->z = (1.0f - ZRecip); // ZBUFFER
00231                 pD3DVerts->rhw = ZRecip;
00232 
00233                 if (AppInfo.FogEnable && !(Flags & DRV_RENDER_POLY_NO_FOG)) // poly fog
00234                 {
00235                         DWORD   FogVal;
00236                         float   Val;
00237 
00238                         Val = pVerts->z;
00239 
00240                         if (Val > AppInfo.FogEnd)
00241                                 Val = AppInfo.FogEnd;
00242 
00243                         FogVal = (DWORD)((AppInfo.FogEnd-Val)/(AppInfo.FogEnd-AppInfo.FogStart)*255.0f);
00244                 
00245                         if (FogVal < 0)
00246                                 FogVal = 0;
00247                         else if (FogVal > 255)
00248                                 FogVal = 255;
00249                 
00250                         pD3DVerts->specular = (FogVal<<24);             // Alpha component in specular is the fog value (0...255)
00251                 }
00252                 else
00253                         pD3DVerts->specular = 0;
00254                 
00255                 // Store the uv's so the prep pass can use them...
00256                 pTVerts->u = pVerts->u;
00257                 pTVerts->v = pVerts->v;
00258 
00259                 pTVerts->Color = Alpha | ((uint32)pVerts->r<<16) | ((uint32)pVerts->g<<8) | (uint32)pVerts->b;
00260 
00261                 pTVerts++;
00262                 pVerts++;        
00263                 pD3DVerts++;
00264 
00265         }
00266         
00267         // Update globals about the world poly cache
00268         WorldCache.NumVerts += NumVerts;
00269         WorldCache.NumPolys++;
00270 
00271         return TRUE;
00272 }

BOOL PCache_Reset void   ) 
 

Definition at line 1200 of file D3D8Drv/Pcache.cpp.

References MiscCache, Misc_Cache::NumPolys, World_Cache::NumPolys, Misc_Cache::NumVerts, World_Cache::NumVerts, TRUE, and WorldCache.

01201 {
01202         WorldCache.NumPolys = 0;
01203         WorldCache.NumVerts = 0;
01204 
01205         MiscCache.NumPolys = 0;
01206         MiscCache.NumVerts = 0;
01207 
01208         return TRUE;
01209 }

BOOL RenderWorldPolys int32  RenderMode  )  [static]
 

Definition at line 931 of file D3D8Drv/Pcache.cpp.

References AppInfo, D3DBlendEnable(), D3DBlendFunc(), D3DDRV, D3DTexturedPoly(), D3DTexWrap(), DRV_RENDER_CLAMP_UV, DRV_RENDER_POLY_NO_FOG, FALSE, World_Poly::FirstVert, World_Poly::Flags, App_Info::FogEnable, GE_FALSE, int32, World_Poly::LInfo, App_Info::lpD3DDevice, geRDriver_THandle::MipData, World_Poly::MipLevel, NULL, World_Cache::NumPolys, World_Cache::NumPolys2, World_Poly::NumVerts, World_Cache::Polys, PREP_WORLD_VERTS_LMAP, PREP_WORLD_VERTS_NORMAL, PREP_WORLD_VERTS_SINGLE_PASS, RENDER_WORLD_POLYS_LMAP, RENDER_WORLD_POLYS_NORMAL, RENDER_WORLD_POLYS_SINGLE_PASS, App_Info::RenderingIsOK, RenderMode, DRV_LInfo::RGBLight, DRV_Driver::SetupLightmap, SetupLMap(), SetupTexture(), THandle_MipData::Slot, World_Cache::SortedPolys, World_Cache::SortedPolys2, SortWorldPolysByHandle(), DRV_LInfo::THandle, World_Poly::THandle, TRUE, TSTAGE_0, TSTAGE_1, World_Cache::Verts, World_PolyPrepVerts(), and WorldCache.

00932 {
00933         World_Poly                      *pPoly;
00934         int32                           i;
00935 
00936         if(!AppInfo.RenderingIsOK)
00937         {
00938                 return  TRUE;
00939         }
00940         switch (RenderMode)
00941         {       
00942                 case RENDER_WORLD_POLYS_NORMAL:
00943                 {
00944                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
00945 
00946                         // Set the default state for the normal poly render mode for the world
00947                         D3DBlendEnable(TRUE);
00948                         D3DBlendFunc (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
00949                         
00950                         // Get the first poly in the sorted list
00951                         SortWorldPolysByHandle();
00952                         
00953                         for (i=0; i< WorldCache.NumPolys; i++)
00954                         {
00955                                 pPoly = WorldCache.SortedPolys[i];
00956 
00957                                 if (pPoly->Flags & DRV_RENDER_CLAMP_UV)
00958                                         D3DTexWrap(0, FALSE);
00959                                 else
00960                                         D3DTexWrap(0, TRUE);
00961 
00962                                 if (!SetupTexture(0, pPoly->THandle, pPoly->MipLevel))
00963                                         return GE_FALSE;
00964 
00965                                 World_PolyPrepVerts(pPoly, PREP_WORLD_VERTS_NORMAL, 0, 0);
00966 
00967                                 D3DTexturedPoly(&WorldCache.Verts[pPoly->FirstVert], pPoly->NumVerts);
00968                         }
00969                         
00970                         break;
00971                 }
00972                 
00973                 case RENDER_WORLD_POLYS_LMAP:
00974                 {
00975                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0);
00976 
00977                         D3DTexWrap(0, FALSE);
00978 
00979                         D3DBlendEnable(TRUE);
00980                         D3DBlendFunc (D3DBLEND_DESTCOLOR, D3DBLEND_ZERO);
00981 
00982                         pPoly = WorldCache.Polys;
00983 
00984                         for (i=0; i< WorldCache.NumPolys; i++, pPoly++)
00985                         {
00986                                 BOOL    Dynamic = 0;
00987 
00988                                 if (!pPoly->LInfo)
00989                                         continue;
00990 
00991                                 // Call the engine to set this sucker up, because it's visible...
00992                                 D3DDRV.SetupLightmap(pPoly->LInfo, &Dynamic);
00993 
00994                                 if (!SetupLMap(0, pPoly->LInfo, 0, Dynamic))
00995                                         return GE_FALSE;
00996 
00997                                 World_PolyPrepVerts(pPoly, PREP_WORLD_VERTS_LMAP, 0, 0);
00998 
00999                                 D3DTexturedPoly(&WorldCache.Verts[pPoly->FirstVert], pPoly->NumVerts);
01000                                 
01001                                 if (pPoly->LInfo->RGBLight[1])
01002                                 {
01003                                         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE);
01004 
01005                                         D3DBlendFunc (D3DBLEND_ONE, D3DBLEND_ONE);                              // Change to a fog state
01006 
01007                                         // For some reason, some cards can't upload data to the same texture twice, and have it take.
01008                                         // So we force Fog maps to use a different slot than the lightmap was using...
01009                                         pPoly->LInfo->THandle->MipData[0].Slot = NULL;
01010 
01011                                         if (!SetupLMap(0, pPoly->LInfo, 1, 1))  // Dynamic is 1, because fog is always dynamic
01012                                                 return GE_FALSE;
01013 
01014                                         D3DTexturedPoly(&WorldCache.Verts[pPoly->FirstVert], pPoly->NumVerts);
01015                 
01016                                         D3DBlendFunc (D3DBLEND_DESTCOLOR, D3DBLEND_ZERO);               // Restore state
01017 
01018                                         if (AppInfo.FogEnable)
01019                                                 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , TRUE);
01020                                 }
01021                         }
01022                         break;
01023                 }
01024 
01025                 case RENDER_WORLD_POLYS_SINGLE_PASS:
01026                 {
01027                         // Setup texture stage states
01028                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
01029                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
01030                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
01031                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
01032                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
01033                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
01034                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE);
01035                                                                          
01036                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1 );
01037                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
01038                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT ); 
01039                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_MODULATE );
01040                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
01041                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT );
01042                         //AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG2 );
01043                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
01044 
01045                         // Setup frame buffer blend modes
01046                         D3DBlendEnable(TRUE);
01047                         D3DBlendFunc (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
01048 
01049                         // Set the default state for the normal poly render mode for the world
01050                         D3DTexWrap(TSTAGE_0, TRUE);
01051                         D3DTexWrap(TSTAGE_1, FALSE);
01052 
01053                         // Sort the list for front back operation to get the least number of world texture misses
01054                         SortWorldPolysByHandle();
01055                         
01056                         // Reset non lightmaps faces to 0
01057                         WorldCache.NumPolys2 = 0;
01058 
01059                         for (i=0; i< WorldCache.NumPolys; i++)
01060                         {
01061                                 BOOL    Dynamic = 0;
01062 
01063                                 pPoly = WorldCache.SortedPolys[i];
01064 
01065                                 if (!pPoly->LInfo)
01066                                 {
01067                                         // Put gouraud only polys in a seperate list, and render last
01068                                         WorldCache.SortedPolys2[WorldCache.NumPolys2++] = pPoly;
01069                                         continue;
01070                                 }
01071 
01072                                 if (pPoly->Flags & DRV_RENDER_CLAMP_UV)
01073                                         D3DTexWrap(TSTAGE_0, FALSE);
01074                                 else
01075                                         D3DTexWrap(TSTAGE_0, TRUE);
01076 
01077                                 if (!SetupTexture(TSTAGE_0, pPoly->THandle, pPoly->MipLevel))
01078                                         return GE_FALSE;                                
01079 
01080                                 // Call the engine to set this sucker up, because it's visible...
01081                                 D3DDRV.SetupLightmap(pPoly->LInfo, &Dynamic);
01082 
01083                                 if (!SetupLMap(TSTAGE_1, pPoly->LInfo, 0, Dynamic))
01084                                         return GE_FALSE;
01085                                         
01086                                 // Prep the verts for a lightmap and texture map
01087                                 World_PolyPrepVerts(pPoly, PREP_WORLD_VERTS_SINGLE_PASS, TSTAGE_0, TSTAGE_1);
01088 
01089                                 if ( (pPoly->Flags & DRV_RENDER_POLY_NO_FOG) && AppInfo.FogEnable) // poly fog
01090                                                 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , FALSE);
01091 
01092                                 // Draw the texture
01093                                 D3DTexturedPoly(&WorldCache.Verts[pPoly->FirstVert], pPoly->NumVerts);
01094 
01095                                 if ( (pPoly->Flags & DRV_RENDER_POLY_NO_FOG) && AppInfo.FogEnable) // poly fog
01096                                                 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , TRUE);
01097 
01098                                 // Render any fog maps
01099                                 if (pPoly->LInfo->RGBLight[1])
01100                                 {
01101                                         D3DBlendFunc (D3DBLEND_ONE, D3DBLEND_ONE);                              // Change to a fog state
01102 
01103                                 #if (TSTAGE_0 == 0)
01104                                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2);
01105                                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
01106 
01107                                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
01108                                 #else
01109                                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
01110                                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
01111                                 #endif
01112 
01113                                         // For some reason, some cards can't upload data to the same texture twice, and have it take.
01114                                         // So we force Fog maps to use a different slot other than what the lightmap was using...
01115                                         pPoly->LInfo->THandle->MipData[0].Slot = NULL;
01116 
01117                                         if (!SetupLMap(TSTAGE_1, pPoly->LInfo, 1, 1))   // Dynamic is 1, because fog is always dynamic
01118                                                 return GE_FALSE;
01119 
01120                                         D3DTexturedPoly(&WorldCache.Verts[pPoly->FirstVert], pPoly->NumVerts);
01121         
01122                                         // Restore states to the last state before fag map
01123                                 #if (TSTAGE_0 == 0)
01124                                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
01125                                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE);
01126         
01127                                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_MODULATE );
01128                                 #else
01129                                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_MODULATE );
01130                                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG2 );
01131                                 #endif
01132 
01133                                         D3DBlendFunc (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
01134                                 }
01135                                 
01136                                 
01137                         }
01138                         
01139                         // Setup for any non-lightmaped faces faces, turn tmu1 off
01140                 #if (TSTAGE_0 == 0)
01141                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
01142                         AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
01143                 #else
01144                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2);
01145                         AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
01146                 #endif
01147 
01148                         // Render all the faces without lightmaps
01149                         for (i=0; i< WorldCache.NumPolys2; i++)
01150                         {
01151                                 BOOL    Dynamic = 0;
01152 
01153                                 pPoly = WorldCache.SortedPolys2[i];
01154 
01155                                 if (pPoly->Flags & DRV_RENDER_CLAMP_UV)
01156                                         D3DTexWrap(TSTAGE_0, FALSE);
01157                                 else
01158                                         D3DTexWrap(TSTAGE_0, TRUE);
01159 
01160                                 if (!SetupTexture(TSTAGE_0, pPoly->THandle, pPoly->MipLevel))
01161                                         return GE_FALSE;                                
01162 
01163                                 // Prep verts as if there was no lightmap
01164                                 World_PolyPrepVerts(pPoly, PREP_WORLD_VERTS_NORMAL, TSTAGE_0, TSTAGE_1);
01165 
01166                                 if ( (pPoly->Flags & DRV_RENDER_POLY_NO_FOG) && AppInfo.FogEnable) // poly fog
01167                                                 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , FALSE);
01168 
01169                                 // Draw the texture
01170                                 D3DTexturedPoly(&WorldCache.Verts[pPoly->FirstVert], pPoly->NumVerts);
01171 
01172                                 if ( (pPoly->Flags & DRV_RENDER_POLY_NO_FOG) && AppInfo.FogEnable) // poly fog
01173                                         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , TRUE);
01174                         }
01175 
01176                         break;                                           
01177                 }
01178 
01179                 default:
01180                         return FALSE;
01181         }
01182 
01183 
01184         return TRUE;
01185 }

geBoolean SetupLMap int32  Stage,
DRV_LInfo LInfo,
int32  LNum,
geBoolean  Dynamic
 

Definition at line 471 of file D3D8Drv/Pcache.cpp.

References CacheInfo, CurrentLRU, D3DCache_SlotGetSurface(), D3DCache_SlotGetTexture(), D3DCache_SlotSetLRU(), D3DErrorToString(), D3DMain_Log(), D3DMain_RestoreAllSurfaces(), D3DSetTexture(), Error, THandle_MipData::Flags, GE_FALSE, GE_TRUE, geBoolean, DRV_CacheInfo::LMapMisses, LoadLMapFromSystem(), geRDriver_THandle::Log, geRDriver_THandle::MipData, NULL, SetupMipData(), THandle_MipData::Slot, SystemToVideo, DRV_LInfo::THandle, and THANDLE_UPDATE.

00472 {
00473         geRDriver_THandle       *THandle;
00474         THandle_MipData         *MipData;
00475 
00476         THandle = LInfo->THandle;
00477         MipData = &THandle->MipData[0];
00478 
00479         if (Dynamic)
00480                 MipData->Flags |= THANDLE_UPDATE;
00481 
00482         if (!SetupMipData(MipData))
00483         {
00484                 MipData->Flags |= THANDLE_UPDATE;               // Force an upload
00485                 CacheInfo.LMapMisses++;
00486         }
00487 
00488         if (MipData->Flags & THANDLE_UPDATE)
00489         {
00490                 HRESULT                                 Error;
00491                 LPDIRECTDRAWSURFACE4    Surface;
00492 
00493                 Surface = D3DCache_SlotGetSurface(MipData->Slot);
00494 
00495                 LoadLMapFromSystem(LInfo, THandle->Log, LNum);
00496 
00497                 Error = Surface->BltFast(0, 0, SystemToVideo[THandle->Log].Surface, NULL, DDBLTFAST_WAIT);
00498                 
00499                 if (Error != DD_OK)
00500                 {
00501                         if(Error==DDERR_SURFACELOST)
00502                         {
00503                                 if (!D3DMain_RestoreAllSurfaces())
00504                                         return GE_FALSE;
00505                         }
00506                         else
00507                         {
00508                                 D3DMain_Log("SetupTexture: System to Video cache Blt failed.\n %s", D3DErrorToString(Error));
00509                                 return GE_FALSE;
00510                         }
00511                 }
00512         }
00513 
00514         if (Dynamic)            // If it was dynmamic, force an update for one more frame
00515                 MipData->Flags |= THANDLE_UPDATE;
00516         else
00517                 MipData->Flags &= ~THANDLE_UPDATE;
00518 
00519         D3DCache_SlotSetLRU(MipData->Slot, CurrentLRU);
00520         D3DSetTexture(Stage, D3DCache_SlotGetTexture(MipData->Slot));
00521 
00522         return GE_TRUE;
00523 }

geBoolean SetupMipData THandle_MipData MipData  ) 
 

Definition at line 452 of file D3D8Drv/Pcache.cpp.

References AppInfo, THandle_MipData::CacheType, D3DCache_SlotGetUserData(), D3DCache_SlotSetUserData(), D3DCache_TypeFindSlot(), GE_FALSE, GE_TRUE, geBoolean, App_Info::lpD3DDevice, and THandle_MipData::Slot.

00453 {
00454         if (!MipData->Slot || D3DCache_SlotGetUserData(MipData->Slot) != MipData)
00455         {
00456                 MipData->Slot = D3DCache_TypeFindSlot(MipData->CacheType);
00457 
00458                 D3DCache_SlotSetUserData(MipData->Slot, MipData);
00459 
00460                 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FLUSHBATCH, 0);
00461 
00462                 return GE_FALSE;
00463         }
00464 
00465         return GE_TRUE;
00466 }

geBoolean SetupTexture int32  Stage,
geRDriver_THandle THandle,
int32  MipLevel
 

Definition at line 528 of file D3D8Drv/Pcache.cpp.

References CacheInfo, CurrentLRU, D3DCache_SlotGetSurface(), D3DCache_SlotGetTexture(), D3DCache_SlotSetLRU(), D3DErrorToString(), D3DMain_Log(), D3DMain_RestoreAllSurfaces(), D3DSetTexture(), Error, FALSE, THandle_MipData::Flags, GE_FALSE, GE_TRUE, geBoolean, geRDriver_THandle::MipData, NULL, SetupMipData(), THandle_MipData::Slot, THandle_MipData::Surface, DRV_CacheInfo::TexMisses, and THANDLE_UPDATE.

00529 {
00530         THandle_MipData         *MipData;
00531 
00532         MipData = &THandle->MipData[MipLevel];
00533         
00534         if (!SetupMipData(MipData))
00535         {
00536                 MipData->Flags |= THANDLE_UPDATE;               // Force an upload
00537                 CacheInfo.TexMisses++;
00538         }
00539 
00540         if (MipData->Flags & THANDLE_UPDATE)
00541         {
00542                 HRESULT                                 Error;
00543                 LPDIRECTDRAWSURFACE4    Surface;
00544 
00545                 Surface = D3DCache_SlotGetSurface(MipData->Slot);
00546 
00547                 Error = Surface->BltFast(0, 0, MipData->Surface, NULL, DDBLTFAST_WAIT);
00548 
00549                 if (Error != DD_OK)
00550                 {
00551                         if(Error==DDERR_SURFACELOST)
00552                         {
00553                                 if (!D3DMain_RestoreAllSurfaces())
00554                                         return FALSE;
00555                         }
00556                         else
00557                         {
00558                                 D3DMain_Log("SetupTexture: System to Video cache Blt failed.\n %s", D3DErrorToString(Error));
00559                                 return GE_FALSE;
00560                         }
00561                 }
00562         }
00563 
00564         MipData->Flags &= ~THANDLE_UPDATE;
00565 
00566         D3DCache_SlotSetLRU(MipData->Slot, CurrentLRU);
00567         D3DSetTexture(Stage, D3DCache_SlotGetTexture(MipData->Slot));
00568 
00569         return GE_TRUE;
00570 }

void SortMiscPolysByHandle void   )  [static]
 

Definition at line 324 of file D3D8Drv/Pcache.cpp.

References int32, MiscBitmapHandleComp(), MiscCache, Misc_Cache::NumPolys, Misc_Cache::Polys, and Misc_Cache::SortedPolys.

00325 {
00326         Misc_Poly       *pPoly;
00327         int32           i;
00328 
00329         pPoly = MiscCache.Polys;
00330 
00331         for (i=0; i<MiscCache.NumPolys; i++)
00332         {
00333                 MiscCache.SortedPolys[i] = pPoly;
00334                 pPoly++;
00335         }
00336         
00337         // Sort the polys
00338         qsort(&MiscCache.SortedPolys, MiscCache.NumPolys, sizeof(MiscCache.SortedPolys[0]), MiscBitmapHandleComp);
00339 }

void SortWorldPolysByHandle void   )  [static]
 

Definition at line 906 of file D3D8Drv/Pcache.cpp.

References BitmapHandleComp(), int32, World_Cache::NumPolys, World_Cache::Polys, World_Cache::SortedPolys, and WorldCache.

00907 {
00908         World_Poly      *pPoly;
00909         int32           i;
00910 
00911         pPoly = WorldCache.Polys;
00912 
00913         for (i=0; i<WorldCache.NumPolys; i++)
00914         {
00915                 WorldCache.SortedPolys[i] = pPoly;
00916                 pPoly++;
00917         }
00918         
00919         // Sort the polys
00920         qsort(&WorldCache.SortedPolys, WorldCache.NumPolys, sizeof(WorldCache.SortedPolys[0]), BitmapHandleComp);
00921 }

geBoolean World_PolyPrepVerts World_Poly pPoly,
int32  PrepMode,
int32  Stage1,
int32  Stage2
 


Variable Documentation

DRV_CacheInfo CacheInfo
 

Definition at line 43 of file D3D8Drv/Pcache.cpp.

uint32 CurrentLRU
 

Definition at line 447 of file D3D8Drv/Pcache.cpp.

Misc_Cache MiscCache [static]
 

Definition at line 148 of file D3D8Drv/Pcache.cpp.

Referenced by PCache_FlushMiscPolys(), PCache_InsertMiscPoly(), PCache_Reset(), and SortMiscPolysByHandle().

D3DTEXTUREHANDLE OldId
 

Definition at line 926 of file D3D8Drv/Pcache.cpp.

LPDIRECT3DTEXTURE2 OldTexture[8]
 

Definition at line 927 of file D3D8Drv/Pcache.cpp.

World_Cache WorldCache [static]
 

Definition at line 112 of file D3D8Drv/Pcache.cpp.

Referenced by ClearWorldCache(), PCache_FlushWorldPolys(), PCache_InsertWorldPoly(), PCache_Reset(), RenderWorldPolys(), and SortWorldPolysByHandle().


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