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

THandle.h File Reference

#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "DCommon.h"
#include "OglMisc.h"

Go to the source code of this file.

Compounds

struct  geRDriver_THandle

Defines

#define MAX_TEXTURE_HANDLES   20000
#define THANDLE_MAX_MIP_LEVELS   16
#define THANDLE_UPDATE   (1<<0)
#define THANDLE_TRANS   (1<<2)
#define THANDLE_LOCKED   (1<<3)
#define THANDLE_UPDATE_LM   (1<<4)

Typedefs

typedef geRDriver_THandle geRDriver_THandle

Functions

geBoolean FreeAllTextureHandles (void)
geBoolean DRIVERCC DrvResetAll (void)
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 **Data)
geBoolean DRIVERCC THandle_UnLock (geRDriver_THandle *THandle, int32 MipLevel)
geBoolean DRIVERCC THandle_GetInfo (geRDriver_THandle *THandle, int32 MipLevel, geRDriver_THandleInfo *Info)
void THandle_Update (geRDriver_THandle *THandle)
void THandle_DownloadLightmap (DRV_LInfo *LInfo)
int32 GetLog (int32 Width, int32 Height)
uint32 Log2 (uint32 P2)
S32 SnapToPower2 (S32 Width)
geBoolean THandle_Startup (void)

Variables

geRDriver_THandle TextureHandles [MAX_TEXTURE_HANDLES]


Define Documentation

#define MAX_TEXTURE_HANDLES   20000
 

Definition at line 30 of file OpenGl/THandle.h.

#define THANDLE_LOCKED   (1<<3)
 

Definition at line 36 of file OpenGl/THandle.h.

#define THANDLE_MAX_MIP_LEVELS   16
 

Definition at line 31 of file OpenGl/THandle.h.

#define THANDLE_TRANS   (1<<2)
 

Definition at line 35 of file OpenGl/THandle.h.

Referenced by CreateTexture(), RenderMiscTexturePoly(), SWTHandle_CreateTexture(), SWTHandle_GetInfo(), and THandle_GetInfo().

#define THANDLE_UPDATE   (1<<0)
 

Definition at line 34 of file OpenGl/THandle.h.

#define THANDLE_UPDATE_LM   (1<<4)
 

Definition at line 37 of file OpenGl/THandle.h.

Referenced by Render_WorldPoly(), and THandle_Create().


Typedef Documentation

typedef struct geRDriver_THandle geRDriver_THandle
 


Function Documentation

geBoolean DRIVERCC DrvResetAll void   ) 
 

Definition at line 89 of file D3ddrv7x.cpp.

00090 {
00091         return D3DMain_Reset();
00092 }

geBoolean FreeAllTextureHandles void   ) 
 

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

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 }

int32 GetLog int32  Width,
int32  Height
 

Definition at line 817 of file D3D7xDrv/D3dcache.cpp.

00818 {
00819         int32   LWidth = SnapToPower2(max(Width, Height));
00820         
00821         return Log2(LWidth);
00822 }

uint32 Log2 uint32  P2  ) 
 

Definition at line 770 of file D3D7xDrv/D3dcache.cpp.

00771 {
00772         uint32          p = 0;
00773         int32           i = 0;
00774         
00775         for (i = P2; i > 0; i>>=1)
00776                 p++;
00777 
00778         return (p-1);
00779 }

S32 SnapToPower2 S32  Width  ) 
 

Definition at line 424 of file THandle.c.

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 }

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 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_DownloadLightmap DRV_LInfo LInfo  ) 
 

Definition at line 404 of file THandle.c.

References geRDriver_THandle::Height, DRV_LInfo::RGBLight, DRV_LInfo::THandle, THandle_Lock(), THandle_UnLock(), and geRDriver_THandle::Width.

Referenced by Render_WorldPoly().

00405 {
00406         GLubyte *tempBits;
00407 
00408         THandle_Lock(LInfo->THandle, 0, (void**)&tempBits);
00409 
00410         memcpy(tempBits, LInfo->RGBLight[0], LInfo->THandle->Width * LInfo->THandle->Height * 3);
00411 
00412         THandle_UnLock(LInfo->THandle, 0);
00413 }

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 **  Data
 

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 }

geBoolean THandle_Startup void   ) 
 

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

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 }

void THandle_Update geRDriver_THandle THandle  ) 
 

Definition at line 314 of file THandle.c.

References CkBlit24_32(), geRDriver_THandle::Data, geRDriver_THandle::Flags, geRDriver_PixelFormat::Flags, GE_PIXELFORMAT_24BIT_RGB, GE_PIXELFORMAT_32BIT_ABGR, geRDriver_THandle::Height, maxTextureSize, NULL, geRDriver_THandle::PaddedHeight, geRDriver_THandle::PaddedWidth, geRDriver_PixelFormat::PixelFormat, geRDriver_THandle::PixelFormat, RDRIVER_PF_2D, THANDLE_UPDATE, and geRDriver_THandle::Width.

Referenced by DrawDecal(), Render_MiscTexturePoly(), Render_WorldPoly(), Render_WorldPolyMultitexture(), and Render_WorldPolyRegular().

00315 {               
00316 
00317         if(THandle->PixelFormat.Flags & RDRIVER_PF_2D)
00318         {
00319                 if(THandle->PixelFormat.PixelFormat == GE_PIXELFORMAT_24BIT_RGB)
00320                 {
00321                         if(THandle->Width <= maxTextureSize && THandle->Height <= maxTextureSize)
00322                         {
00323                                 GLubyte *dest;
00324 
00325                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00326                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00327                                 
00328                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00329                                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00330                         
00331                                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 0.5f);
00332 
00333                                 dest = malloc(THandle->PaddedWidth * THandle->PaddedHeight * 4);
00334 
00335                                 CkBlit24_32(dest, THandle->PaddedWidth, THandle->PaddedHeight, THandle->Data[0], 
00336                                         THandle->Width, THandle->Height);
00337 
00338                                 glTexImage2D(GL_TEXTURE_2D, 0, 4, THandle->PaddedWidth, THandle->PaddedHeight, 
00339                                         0, GL_RGBA, GL_UNSIGNED_BYTE, dest); 
00340 
00341                                 free(dest);
00342                         }
00343                         else
00344                         {
00345                                 if(THandle->Data[1] != NULL)
00346                                 {
00347                                         free(THandle->Data[1]);
00348                                 }
00349 
00350                                 THandle->Data[1] = malloc(THandle->Width * THandle->Height * 4);
00351 
00352                                 CkBlit24_32(THandle->Data[1], THandle->Width, THandle->Height, THandle->Data[0],
00353                                         THandle->Width, THandle->Height);
00354                         }
00355                 }
00356         }
00357         else
00358         {
00359 #ifdef USE_LINEAR_INTERPOLATION 
00360  #ifdef TRILINEAR_INTERPOLATION
00361                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
00362                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00363  #else 
00364                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
00365                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00366  #endif
00367 #else
00368  #ifdef TRILINEAR_INTERPOLATION
00369                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
00370                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00371  #else
00372                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
00373                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00374  #endif
00375 #endif 
00376 
00377                 if(THandle->PixelFormat.PixelFormat == GE_PIXELFORMAT_32BIT_ABGR)
00378                 {
00379                         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
00380                         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
00381                         
00382                         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 1.0f);
00383                         
00384                         gluBuild2DMipmaps(GL_TEXTURE_2D, 4, THandle->Width, THandle->Height, GL_RGBA,
00385                                 GL_UNSIGNED_BYTE, THandle->Data[0]);
00386                 }
00387                 else
00388                 {
00389                         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00390                         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00391                         
00392                         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 0.0f);
00393                         
00394                         gluBuild2DMipmaps(GL_TEXTURE_2D, 3, THandle->Width, THandle->Height, 
00395                                 GL_RGB, GL_UNSIGNED_BYTE, THandle->Data[0]);
00396                 }
00397         }
00398 
00399         THandle->Flags &= ~THANDLE_UPDATE;
00400 }


Variable Documentation

geRDriver_THandle TextureHandles[MAX_TEXTURE_HANDLES]
 

Definition at line 51 of file OpenGl/THandle.h.


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