//============================================================================================ // Create2DTHandle //============================================================================================ geRDriver_THandle *Create2DTHandle(geRDriver_THandle *THandle, int32 Width, int32 Height, int32 NumMipLevels, const geRDriver_PixelFormat *PixelFormat) { assert(NumMipLevels < THANDLE_MAX_MIP_LEVELS); assert(NumMipLevels == 1); // Save some info about the lightmap THandle->Width = Width; THandle->Height = Height; THandle->NumMipLevels = (uint8)NumMipLevels; THandle->Log = (uint8)GetLog(Width, Height); THandle->Stride = Width; // Create the surfaces to hold all the mips THandle->MipData = (THandle_MipData*)malloc(sizeof(THandle_MipData)*NumMipLevels); memset(THandle->MipData, 0, sizeof(THandle_MipData)*NumMipLevels); if (!THandle->MipData) { THandle_Destroy(THandle); return NULL; } if (!THandle_CreateSurfaces(&THandle->MipData[0], Width, Height, &CurrentSurfDesc, GE_TRUE, 0)) { THandle_Destroy(THandle); return NULL; } return THandle; }
//============================================================================================ // Create3DTHandle //============================================================================================ geRDriver_THandle *Create3DTHandle(geRDriver_THandle *THandle, int32 Width, int32 Height, int32 NumMipLevels, const geRDriver_PixelFormat *PixelFormat) { int32 Size, i; assert(NumMipLevels < THANDLE_MAX_MIP_LEVELS); assert(NumMipLevels <= 4); // Store width/height info THandle->Width = Width; THandle->Height = Height; THandle->NumMipLevels = (uint8)NumMipLevels; THandle->Log = (uint8)GetLog(Width, Height); THandle->Stride = (1<<THandle->Log); // Create the surfaces to hold all the mips THandle->MipData = (THandle_MipData*)malloc(sizeof(THandle_MipData)*NumMipLevels); memset(THandle->MipData, 0, sizeof(THandle_MipData)*NumMipLevels); if (!THandle->MipData) { THandle_Destroy(THandle); return NULL; } Size = 1<<THandle->Log; // Create all the surfaces for each mip level for (i=0; i< NumMipLevels; i++) { int32 Stage; if (!THandle_CreateSurfaces(&THandle->MipData[i], Size, Size, &CurrentSurfDesc, GE_FALSE, 0)) { THandle_Destroy(THandle); return NULL; } // get a cache type for this surface since it is a 3d surface, and will need to be cached on the video card //THandle->MipData[i].CacheType = D3DCache_TypeCreate(TextureCache, Size, Size, NumMipLevels, &CurrentSurfDesc); // We can use 1 miplevel for the type, since we are createing types for each miplevel... if (AppInfo.CanDoMultiTexture) Stage = TSTAGE_0; else Stage = 0; THandle->MipData[i].CacheType = D3DCache_TypeCreate(TextureCache, Size, Size, 1, Stage, &CurrentSurfDesc); if (!THandle->MipData[i].CacheType) { THandle_Destroy(THandle); return NULL; } Size>>=1; } return THandle; }
// Cleanup all currently in-use texture handles geBoolean FreeAllTextureHandles(void) { int32 i; geRDriver_THandle *pTHandle; pTHandle = TextureHandles; for(i = 0; i < MAX_TEXTURE_HANDLES; i++, pTHandle++) { if(!pTHandle->Active) { continue; } THandle_Destroy(pTHandle); } glDeleteTextures(1, (const GLuint*)&decalTexObj); decalTexObj = -1; boundTexture = -1; boundTexture2 = -1; return GE_TRUE; }
//============================================================================================ // FreeAllTextureHandles //============================================================================================ geBoolean FreeAllTextureHandles(void) { int32 i; geRDriver_THandle *pHandle; pHandle = TextureHandles; for (i=0; i< MAX_TEXTURE_HANDLES; i++, pHandle++) { if (!pHandle->Active) continue; if (!THandle_Destroy(pHandle)) return GE_FALSE; } return GE_TRUE; }
//============================================================================================ // CreateLightmapTHandle //============================================================================================ geRDriver_THandle *CreateLightmapTHandle(geRDriver_THandle *THandle, int32 Width, int32 Height, int32 NumMipLevels, const geRDriver_PixelFormat *PixelFormat) { int32 Size, Stage; assert(NumMipLevels < THANDLE_MAX_MIP_LEVELS); assert(NumMipLevels == 1); // Save some info about the lightmap THandle->Width = Width; THandle->Height = Height; THandle->NumMipLevels = (uint8)NumMipLevels; THandle->Log = (uint8)GetLog(Width, Height); THandle->Stride = 1<<THandle->Log; assert(THandle->Log < MAX_LMAP_LOG_SIZE); Size = 1<<THandle->Log; THandle->MipData = (THandle_MipData*)malloc(sizeof(THandle_MipData)*NumMipLevels); memset(THandle->MipData, 0, sizeof(THandle_MipData)*NumMipLevels); THandle->MipData[0].Flags = THANDLE_UPDATE; #ifdef D3D_MANAGE_TEXTURES #ifndef USE_TPAGES { int32 Stage; if (AppInfo.CanDoMultiTexture) Stage = STAGE_1; else Stage = 0; if (!THandle_CreateSurfaces(&THandle->MipData[0], Size, Size, &CurrentSurfDesc, GE_FALSE, Stage)) { THandle_Destroy(THandle); return NULL; } D3DSetTexture(0, THandle->MipData[0].Texture); } #endif #endif if (AppInfo.CanDoMultiTexture) Stage = TSTAGE_1; else Stage = 0; #ifdef USE_ONE_CACHE THandle->MipData[0].CacheType = D3DCache_TypeCreate(TextureCache, Size, Size, NumMipLevels, Stage, &CurrentSurfDesc); #else THandle->MipData[0].CacheType = D3DCache_TypeCreate(LMapCache, Size, Size, NumMipLevels, Stage, &CurrentSurfDesc); #endif if (!THandle->MipData[0].CacheType) { THandle_Destroy(THandle); return NULL; } return THandle; }