doom3-bfg/neo/renderer/ImageManager.cpp

1019 lines
24 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2012-11-26 18:58:24 +00:00
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
2012-11-26 18:58:24 +00:00
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#pragma hdrstop
#include "../idlib/precompiled.h"
#include "tr_local.h"
// do this with a pointer, in case we want to make the actual manager
// a private virtual subclass
idImageManager imageManager;
idImageManager* globalImages = &imageManager;
2012-11-26 18:58:24 +00:00
idCVar preLoad_Images( "preLoad_Images", "1", CVAR_SYSTEM | CVAR_BOOL, "preload images during beginlevelload" );
/*
===============
R_ReloadImages_f
Regenerate all images that came directly from files that have changed, so
any saved changes will show up in place.
New r_texturesize/r_texturedepth variables will take effect on reload
reloadImages <all>
===============
*/
void R_ReloadImages_f( const idCmdArgs& args )
{
2012-11-26 18:58:24 +00:00
bool all = false;
if( args.Argc() == 2 )
{
if( !idStr::Icmp( args.Argv( 1 ), "all" ) )
{
2012-11-26 18:58:24 +00:00
all = true;
}
else
{
2012-11-26 18:58:24 +00:00
common->Printf( "USAGE: reloadImages <all>\n" );
return;
}
}
2012-11-26 18:58:24 +00:00
globalImages->ReloadImages( all );
}
typedef struct
{
idImage* image;
2012-11-26 18:58:24 +00:00
int size;
int index;
} sortedImage_t;
/*
=======================
R_QsortImageSizes
=======================
*/
static int R_QsortImageSizes( const void* a, const void* b )
{
const sortedImage_t* ea, *eb;
ea = ( sortedImage_t* )a;
eb = ( sortedImage_t* )b;
if( ea->size > eb->size )
{
2012-11-26 18:58:24 +00:00
return -1;
}
if( ea->size < eb->size )
{
2012-11-26 18:58:24 +00:00
return 1;
}
return idStr::Icmp( ea->image->GetName(), eb->image->GetName() );
}
/*
=======================
R_QsortImageName
=======================
*/
static int R_QsortImageName( const void* a, const void* b )
{
const sortedImage_t* ea, *eb;
ea = ( sortedImage_t* )a;
eb = ( sortedImage_t* )b;
2012-11-26 18:58:24 +00:00
return idStr::Icmp( ea->image->GetName(), eb->image->GetName() );
}
/*
===============
R_ListImages_f
===============
*/
void R_ListImages_f( const idCmdArgs& args )
{
2012-11-26 18:58:24 +00:00
int i, partialSize;
idImage* image;
2012-11-26 18:58:24 +00:00
int totalSize;
int count = 0;
bool uncompressedOnly = false;
bool unloaded = false;
bool failed = false;
bool sorted = false;
bool duplicated = false;
bool overSized = false;
bool sortByName = false;
if( args.Argc() == 1 )
{
}
else if( args.Argc() == 2 )
{
if( idStr::Icmp( args.Argv( 1 ), "uncompressed" ) == 0 )
{
2012-11-26 18:58:24 +00:00
uncompressedOnly = true;
}
else if( idStr::Icmp( args.Argv( 1 ), "sorted" ) == 0 )
{
2012-11-26 18:58:24 +00:00
sorted = true;
}
else if( idStr::Icmp( args.Argv( 1 ), "namesort" ) == 0 )
{
2012-11-26 18:58:24 +00:00
sortByName = true;
}
else if( idStr::Icmp( args.Argv( 1 ), "unloaded" ) == 0 )
{
2012-11-26 18:58:24 +00:00
unloaded = true;
}
else if( idStr::Icmp( args.Argv( 1 ), "duplicated" ) == 0 )
{
2012-11-26 18:58:24 +00:00
duplicated = true;
}
else if( idStr::Icmp( args.Argv( 1 ), "oversized" ) == 0 )
{
2012-11-26 18:58:24 +00:00
sorted = true;
overSized = true;
}
else
{
2012-11-26 18:58:24 +00:00
failed = true;
}
}
else
{
2012-11-26 18:58:24 +00:00
failed = true;
}
if( failed )
{
2012-11-26 18:58:24 +00:00
common->Printf( "usage: listImages [ sorted | namesort | unloaded | duplicated | showOverSized ]\n" );
return;
}
const char* header = " -w-- -h-- filt -fmt-- wrap size --name-------\n";
2012-11-26 18:58:24 +00:00
common->Printf( "\n%s", header );
2012-11-26 18:58:24 +00:00
totalSize = 0;
sortedImage_t* sortedArray = ( sortedImage_t* )alloca( sizeof( sortedImage_t ) * globalImages->images.Num() );
for( i = 0 ; i < globalImages->images.Num() ; i++ )
{
2012-11-26 18:58:24 +00:00
image = globalImages->images[ i ];
if( uncompressedOnly )
{
if( image->IsCompressed() )
{
2012-11-26 18:58:24 +00:00
continue;
}
}
if( unloaded == image->IsLoaded() )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-11-26 18:58:24 +00:00
// only print duplicates (from mismatched wrap / clamp, etc)
if( duplicated )
{
2012-11-26 18:58:24 +00:00
int j;
for( j = i + 1 ; j < globalImages->images.Num() ; j++ )
{
if( idStr::Icmp( image->GetName(), globalImages->images[ j ]->GetName() ) == 0 )
{
2012-11-26 18:58:24 +00:00
break;
}
}
if( j == globalImages->images.Num() )
{
2012-11-26 18:58:24 +00:00
continue;
}
}
if( sorted || sortByName )
{
2012-11-26 18:58:24 +00:00
sortedArray[count].image = image;
sortedArray[count].size = image->StorageSize();
sortedArray[count].index = i;
}
else
{
2012-11-26 18:58:24 +00:00
common->Printf( "%4i:", i );
image->Print();
}
totalSize += image->StorageSize();
count++;
}
if( sorted || sortByName )
{
if( sortByName )
{
2012-11-26 18:58:24 +00:00
qsort( sortedArray, count, sizeof( sortedImage_t ), R_QsortImageName );
}
else
{
2012-11-26 18:58:24 +00:00
qsort( sortedArray, count, sizeof( sortedImage_t ), R_QsortImageSizes );
}
partialSize = 0;
for( i = 0 ; i < count ; i++ )
{
2012-11-26 18:58:24 +00:00
common->Printf( "%4i:", sortedArray[i].index );
sortedArray[i].image->Print();
partialSize += sortedArray[i].image->StorageSize();
if( ( ( i + 1 ) % 10 ) == 0 )
{
common->Printf( "-------- %5.1f of %5.1f megs --------\n",
partialSize / ( 1024 * 1024.0 ), totalSize / ( 1024 * 1024.0 ) );
2012-11-26 18:58:24 +00:00
}
}
}
2012-11-26 18:58:24 +00:00
common->Printf( "%s", header );
common->Printf( " %i images (%i total)\n", count, globalImages->images.Num() );
common->Printf( " %5.1f total megabytes of images\n\n\n", totalSize / ( 1024 * 1024.0 ) );
2012-11-26 18:58:24 +00:00
}
/*
==============
AllocImage
Allocates an idImage, adds it to the list,
copies the name, and adds it to the hash chain.
==============
*/
idImage* idImageManager::AllocImage( const char* name )
{
if( strlen( name ) >= MAX_IMAGE_NAME )
{
common->Error( "idImageManager::AllocImage: \"%s\" is too long\n", name );
2012-11-26 18:58:24 +00:00
}
2012-11-26 18:58:24 +00:00
int hash = idStr( name ).FileNameHash();
idImage* image = new( TAG_IMAGE ) idImage( name );
2012-11-26 18:58:24 +00:00
imageHash.Add( hash, images.Append( image ) );
2012-11-26 18:58:24 +00:00
return image;
}
/*
==============
AllocStandaloneImage
Allocates an idImage,does not add it to the list or hash chain
==============
*/
idImage* idImageManager::AllocStandaloneImage( const char* name )
{
if( strlen( name ) >= MAX_IMAGE_NAME )
{
common->Error( "idImageManager::AllocImage: \"%s\" is too long\n", name );
}
idImage* image = new( TAG_IMAGE ) idImage( name );
2012-11-26 18:58:24 +00:00
return image;
}
/*
==================
ImageFromFunction
Images that are procedurally generated are allways specified
with a callback which must work at any time, allowing the OpenGL
system to be completely regenerated if needed.
==================
*/
idImage* idImageManager::ImageFromFunction( const char* _name, void ( *generatorFunction )( idImage* image ) )
{
2012-11-26 18:58:24 +00:00
// strip any .tga file extensions from anywhere in the _name
idStr name = _name;
name.Replace( ".tga", "" );
name.BackSlashesToSlashes();
2012-11-26 18:58:24 +00:00
// see if the image already exists
int hash = name.FileNameHash();
for( int i = imageHash.First( hash ); i != -1; i = imageHash.Next( i ) )
{
idImage* image = images[i];
if( name.Icmp( image->GetName() ) == 0 )
{
if( image->generatorFunction != generatorFunction )
{
2012-11-26 18:58:24 +00:00
common->DPrintf( "WARNING: reused image %s with mixed generators\n", name.c_str() );
}
return image;
}
}
2012-11-26 18:58:24 +00:00
// create the image and issue the callback
idImage* image = AllocImage( name );
2012-11-26 18:58:24 +00:00
image->generatorFunction = generatorFunction;
2012-11-26 18:58:24 +00:00
// check for precompressed, load is from the front end
image->referencedOutsideLevelLoad = true;
image->ActuallyLoadImage( false );
2012-11-26 18:58:24 +00:00
return image;
}
/*
===============
GetImageWithParameters
==============
*/
idImage* idImageManager::GetImageWithParameters( const char* _name, textureFilter_t filter, textureRepeat_t repeat, textureUsage_t usage, cubeFiles_t cubeMap ) const
{
if( !_name || !_name[0] || idStr::Icmp( _name, "default" ) == 0 || idStr::Icmp( _name, "_default" ) == 0 )
{
2012-11-26 18:58:24 +00:00
declManager->MediaPrint( "DEFAULTED\n" );
return globalImages->defaultImage;
}
if( idStr::Icmpn( _name, "fonts", 5 ) == 0 || idStr::Icmpn( _name, "newfonts", 8 ) == 0 )
{
2012-11-26 18:58:24 +00:00
usage = TD_FONT;
}
if( idStr::Icmpn( _name, "lights", 6 ) == 0 )
{
2012-11-26 18:58:24 +00:00
usage = TD_LIGHT;
}
// strip any .tga file extensions from anywhere in the _name, including image program parameters
idStrStatic< MAX_OSPATH > name = _name;
name.Replace( ".tga", "" );
name.BackSlashesToSlashes();
int hash = name.FileNameHash();
for( int i = imageHash.First( hash ); i != -1; i = imageHash.Next( i ) )
{
idImage* image = images[i];
if( name.Icmp( image->GetName() ) == 0 )
{
2012-11-26 18:58:24 +00:00
// the built in's, like _white and _flat always match the other options
if( name[0] == '_' )
{
2012-11-26 18:58:24 +00:00
return image;
}
if( image->cubeFiles != cubeMap )
{
2012-11-26 18:58:24 +00:00
common->Error( "Image '%s' has been referenced with conflicting cube map states", _name );
}
if( image->filter != filter || image->repeat != repeat )
{
2012-11-26 18:58:24 +00:00
// we might want to have the system reset these parameters on every bind and
// share the image data
continue;
}
if( image->usage != usage )
{
2012-11-26 18:58:24 +00:00
// If an image is used differently then we need 2 copies of it because usage affects the way it's compressed and swizzled
continue;
}
return image;
}
}
return NULL;
}
/*
===============
ImageFromFile
Finds or loads the given image, always returning a valid image pointer.
Loading of the image may be deferred for dynamic loading.
==============
*/
idImage* idImageManager::ImageFromFile( const char* _name, textureFilter_t filter,
textureRepeat_t repeat, textureUsage_t usage, cubeFiles_t cubeMap )
{
2012-11-26 18:58:24 +00:00
if( !_name || !_name[0] || idStr::Icmp( _name, "default" ) == 0 || idStr::Icmp( _name, "_default" ) == 0 )
{
2012-11-26 18:58:24 +00:00
declManager->MediaPrint( "DEFAULTED\n" );
return globalImages->defaultImage;
}
if( idStr::Icmpn( _name, "fonts", 5 ) == 0 || idStr::Icmpn( _name, "newfonts", 8 ) == 0 )
{
2012-11-26 18:58:24 +00:00
usage = TD_FONT;
}
if( idStr::Icmpn( _name, "lights", 6 ) == 0 )
{
2012-11-26 18:58:24 +00:00
usage = TD_LIGHT;
}
2012-11-26 18:58:24 +00:00
// strip any .tga file extensions from anywhere in the _name, including image program parameters
idStrStatic< MAX_OSPATH > name = _name;
name.Replace( ".tga", "" );
name.BackSlashesToSlashes();
2012-11-26 18:58:24 +00:00
//
// see if the image is already loaded, unless we
// are in a reloadImages call
//
int hash = name.FileNameHash();
for( int i = imageHash.First( hash ); i != -1; i = imageHash.Next( i ) )
{
idImage* image = images[i];
if( name.Icmp( image->GetName() ) == 0 )
{
2012-11-26 18:58:24 +00:00
// the built in's, like _white and _flat always match the other options
if( name[0] == '_' )
{
2012-11-26 18:58:24 +00:00
return image;
}
if( image->cubeFiles != cubeMap )
{
2012-11-26 18:58:24 +00:00
common->Error( "Image '%s' has been referenced with conflicting cube map states", _name );
}
if( image->filter != filter || image->repeat != repeat )
{
2012-11-26 18:58:24 +00:00
// we might want to have the system reset these parameters on every bind and
// share the image data
continue;
}
if( image->usage != usage )
{
2012-11-26 18:58:24 +00:00
// If an image is used differently then we need 2 copies of it because usage affects the way it's compressed and swizzled
continue;
}
2012-11-26 18:58:24 +00:00
image->usage = usage;
image->levelLoadReferenced = true;
if( ( !insideLevelLoad || preloadingMapImages ) && !image->IsLoaded() )
{
2012-11-26 18:58:24 +00:00
image->referencedOutsideLevelLoad = ( !insideLevelLoad && !preloadingMapImages );
image->ActuallyLoadImage( false ); // load is from front end
declManager->MediaPrint( "%ix%i %s (reload for mixed referneces)\n", image->GetUploadWidth(), image->GetUploadHeight(), image->GetName() );
}
return image;
}
}
2012-11-26 18:58:24 +00:00
//
// create a new image
//
idImage* image = AllocImage( name );
2012-11-26 18:58:24 +00:00
image->cubeFiles = cubeMap;
image->usage = usage;
image->filter = filter;
image->repeat = repeat;
2012-11-26 18:58:24 +00:00
image->levelLoadReferenced = true;
2012-11-26 18:58:24 +00:00
// load it if we aren't in a level preload
if( !insideLevelLoad || preloadingMapImages )
{
2012-11-26 18:58:24 +00:00
image->referencedOutsideLevelLoad = ( !insideLevelLoad && !preloadingMapImages );
image->ActuallyLoadImage( false ); // load is from front end
declManager->MediaPrint( "%ix%i %s\n", image->GetUploadWidth(), image->GetUploadHeight(), image->GetName() );
}
else
{
2012-11-26 18:58:24 +00:00
declManager->MediaPrint( "%s\n", image->GetName() );
}
2012-11-26 18:58:24 +00:00
return image;
}
/*
========================
idImageManager::ScratchImage
========================
*/
idImage* idImageManager::ScratchImage( const char* _name, idImageOpts* imgOpts, textureFilter_t filter, textureRepeat_t repeat, textureUsage_t usage )
{
if( !_name || !_name[0] )
{
2012-11-26 18:58:24 +00:00
idLib::FatalError( "idImageManager::ScratchImage called with empty name" );
}
if( imgOpts == NULL )
{
2012-11-26 18:58:24 +00:00
idLib::FatalError( "idImageManager::ScratchImage called with NULL imgOpts" );
}
2012-11-26 18:58:24 +00:00
idStr name = _name;
2012-11-26 18:58:24 +00:00
//
// see if the image is already loaded, unless we
// are in a reloadImages call
//
int hash = name.FileNameHash();
for( int i = imageHash.First( hash ); i != -1; i = imageHash.Next( i ) )
{
idImage* image = images[i];
if( name.Icmp( image->GetName() ) == 0 )
{
2012-11-26 18:58:24 +00:00
// the built in's, like _white and _flat always match the other options
if( name[0] == '_' )
{
2012-11-26 18:58:24 +00:00
return image;
}
if( image->filter != filter || image->repeat != repeat )
{
2012-11-26 18:58:24 +00:00
// we might want to have the system reset these parameters on every bind and
// share the image data
continue;
}
if( image->usage != usage )
{
2012-11-26 18:58:24 +00:00
// If an image is used differently then we need 2 copies of it because usage affects the way it's compressed and swizzled
continue;
}
2012-11-26 18:58:24 +00:00
image->usage = usage;
image->levelLoadReferenced = true;
image->referencedOutsideLevelLoad = true;
return image;
}
}
2012-11-26 18:58:24 +00:00
// clamp is the only repeat mode that makes sense for cube maps, but
// some platforms let them stay in repeat mode and get border seam issues
if( imgOpts->textureType == TT_CUBIC && repeat != TR_CLAMP )
{
2012-11-26 18:58:24 +00:00
repeat = TR_CLAMP;
}
2012-11-26 18:58:24 +00:00
//
// create a new image
//
idImage* newImage = AllocImage( name );
if( newImage != NULL )
{
2012-11-26 18:58:24 +00:00
newImage->AllocImage( *imgOpts, filter, repeat );
}
return newImage;
}
/*
===============
idImageManager::GetImage
===============
*/
idImage* idImageManager::GetImage( const char* _name ) const
{
2012-11-26 18:58:24 +00:00
if( !_name || !_name[0] || idStr::Icmp( _name, "default" ) == 0 || idStr::Icmp( _name, "_default" ) == 0 )
{
2012-11-26 18:58:24 +00:00
declManager->MediaPrint( "DEFAULTED\n" );
return globalImages->defaultImage;
}
2012-11-26 18:58:24 +00:00
// strip any .tga file extensions from anywhere in the _name, including image program parameters
idStr name = _name;
name.Replace( ".tga", "" );
name.BackSlashesToSlashes();
2012-11-26 18:58:24 +00:00
//
// look in loaded images
//
int hash = name.FileNameHash();
for( int i = imageHash.First( hash ); i != -1; i = imageHash.Next( i ) )
{
idImage* image = images[i];
if( name.Icmp( image->GetName() ) == 0 )
{
2012-11-26 18:58:24 +00:00
return image;
}
}
2012-11-26 18:58:24 +00:00
return NULL;
}
/*
===============
PurgeAllImages
===============
*/
void idImageManager::PurgeAllImages()
{
2012-11-26 18:58:24 +00:00
int i;
idImage* image;
for( i = 0; i < images.Num() ; i++ )
{
2012-11-26 18:58:24 +00:00
image = images[i];
image->PurgeImage();
}
}
/*
===============
ReloadImages
===============
*/
void idImageManager::ReloadImages( bool all )
{
for( int i = 0 ; i < globalImages->images.Num() ; i++ )
{
2012-11-26 18:58:24 +00:00
globalImages->images[ i ]->Reload( all );
}
}
/*
===============
R_CombineCubeImages_f
Used to combine animations of six separate tga files into
a serials of 6x taller tga files, for preparation to roq compress
===============
*/
void R_CombineCubeImages_f( const idCmdArgs& args )
{
if( args.Argc() != 2 )
{
2012-11-26 18:58:24 +00:00
common->Printf( "usage: combineCubeImages <baseName>\n" );
common->Printf( " combines basename[1-6][0001-9999].tga to basenameCM[0001-9999].tga\n" );
common->Printf( " 1: forward 2:right 3:back 4:left 5:up 6:down\n" );
return;
}
2012-11-26 18:58:24 +00:00
idStr baseName = args.Argv( 1 );
common->SetRefreshOnPrint( true );
for( int frameNum = 1 ; frameNum < 10000 ; frameNum++ )
{
2012-11-26 18:58:24 +00:00
char filename[MAX_IMAGE_NAME];
byte* pics[6];
2012-11-26 18:58:24 +00:00
int width = 0, height = 0;
int side;
int orderRemap[6] = { 1, 3, 4, 2, 5, 6 };
for( side = 0 ; side < 6 ; side++ )
{
2012-11-26 18:58:24 +00:00
sprintf( filename, "%s%i%04i.tga", baseName.c_str(), orderRemap[side], frameNum );
2012-11-26 18:58:24 +00:00
common->Printf( "reading %s\n", filename );
R_LoadImage( filename, &pics[side], &width, &height, NULL, true );
if( !pics[side] )
{
2012-11-26 18:58:24 +00:00
common->Printf( "not found.\n" );
break;
}
2012-11-26 18:58:24 +00:00
// convert from "camera" images to native cube map images
switch( side )
{
case 0: // forward
R_RotatePic( pics[side], width );
break;
case 1: // back
R_RotatePic( pics[side], width );
R_HorizontalFlip( pics[side], width, height );
R_VerticalFlip( pics[side], width, height );
break;
case 2: // left
R_VerticalFlip( pics[side], width, height );
break;
case 3: // right
R_HorizontalFlip( pics[side], width, height );
break;
case 4: // up
R_RotatePic( pics[side], width );
break;
case 5: // down
R_RotatePic( pics[side], width );
break;
2012-11-26 18:58:24 +00:00
}
}
if( side != 6 )
{
for( int i = 0 ; i < side ; side++ )
{
2012-11-26 18:58:24 +00:00
Mem_Free( pics[side] );
}
break;
}
idTempArray<byte> buf( width * height * 6 * 4 );
byte* combined = ( byte* )buf.Ptr();
for( side = 0 ; side < 6 ; side++ )
{
memcpy( combined + width * height * 4 * side, pics[side], width * height * 4 );
2012-11-26 18:58:24 +00:00
Mem_Free( pics[side] );
}
sprintf( filename, "%sCM%04i.tga", baseName.c_str(), frameNum );
2012-11-26 18:58:24 +00:00
common->Printf( "writing %s\n", filename );
R_WriteTGA( filename, combined, width, height * 6 );
2012-11-26 18:58:24 +00:00
}
common->SetRefreshOnPrint( false );
}
/*
===============
UnbindAll
===============
*/
void idImageManager::UnbindAll()
{
2012-11-26 18:58:24 +00:00
int oldTMU = backEnd.glState.currenttmu;
for( int i = 0; i < MAX_PROG_TEXTURE_PARMS; ++i )
{
2012-11-26 18:58:24 +00:00
backEnd.glState.currenttmu = i;
BindNull();
}
backEnd.glState.currenttmu = oldTMU;
}
/*
===============
BindNull
===============
*/
void idImageManager::BindNull()
{
2012-11-26 18:58:24 +00:00
RENDERLOG_PRINTF( "BindNull()\n" );
2012-11-26 18:58:24 +00:00
}
/*
===============
Init
===============
*/
void idImageManager::Init()
{
2012-11-26 18:58:24 +00:00
images.Resize( 1024, 1024 );
imageHash.ResizeIndex( 1024 );
2012-11-26 18:58:24 +00:00
CreateIntrinsicImages();
2012-11-26 18:58:24 +00:00
cmdSystem->AddCommand( "reloadImages", R_ReloadImages_f, CMD_FL_RENDERER, "reloads images" );
cmdSystem->AddCommand( "listImages", R_ListImages_f, CMD_FL_RENDERER, "lists images" );
cmdSystem->AddCommand( "combineCubeImages", R_CombineCubeImages_f, CMD_FL_RENDERER, "combines six images for roq compression" );
2012-11-26 18:58:24 +00:00
// should forceLoadImages be here?
}
/*
===============
Shutdown
===============
*/
void idImageManager::Shutdown()
{
2012-11-26 18:58:24 +00:00
images.DeleteContents( true );
imageHash.Clear();
2012-11-26 18:58:24 +00:00
}
/*
====================
idImageManager::BeginLevelLoad
Frees all images used by the previous level
====================
*/
void idImageManager::BeginLevelLoad()
{
2012-11-26 18:58:24 +00:00
insideLevelLoad = true;
for( int i = 0 ; i < images.Num() ; i++ )
{
idImage* image = images[ i ];
2012-11-26 18:58:24 +00:00
// generator function images are always kept around
if( image->generatorFunction )
{
2012-11-26 18:58:24 +00:00
continue;
}
if( !image->referencedOutsideLevelLoad && image->IsLoaded() )
{
2012-11-26 18:58:24 +00:00
image->PurgeImage();
//idLib::Printf( "purging %s\n", image->GetName() );
}
else
{
2012-11-26 18:58:24 +00:00
//idLib::Printf( "not purging %s\n", image->GetName() );
}
2012-11-26 18:58:24 +00:00
image->levelLoadReferenced = false;
}
}
/*
====================
idImageManager::ExcludePreloadImage
====================
*/
bool idImageManager::ExcludePreloadImage( const char* name )
{
2012-11-26 18:58:24 +00:00
idStrStatic< MAX_OSPATH > imgName = name;
imgName.ToLower();
if( imgName.Find( "newfonts/", false ) >= 0 )
{
2012-11-26 18:58:24 +00:00
return true;
}
if( imgName.Find( "generated/swf/", false ) >= 0 )
{
2012-11-26 18:58:24 +00:00
return true;
}
if( imgName.Find( "/loadscreens/", false ) >= 0 )
{
2012-11-26 18:58:24 +00:00
return true;
}
return false;
}
/*
====================
idImageManager::Preload
====================
*/
void idImageManager::Preload( const idPreloadManifest& manifest, const bool& mapPreload )
{
if( preLoad_Images.GetBool() && manifest.NumResources() > 0 )
{
2012-11-26 18:58:24 +00:00
// preload this levels images
common->Printf( "Preloading images...\n" );
preloadingMapImages = mapPreload;
int start = Sys_Milliseconds();
int numLoaded = 0;
2012-11-26 18:58:24 +00:00
//fileSystem->StartPreload( preloadImageFiles );
for( int i = 0; i < manifest.NumResources(); i++ )
{
const preloadEntry_s& p = manifest.GetPreloadByIndex( i );
if( p.resType == PRELOAD_IMAGE && !ExcludePreloadImage( p.resourceName ) )
{
2012-11-26 18:58:24 +00:00
globalImages->ImageFromFile( p.resourceName, ( textureFilter_t )p.imgData.filter, ( textureRepeat_t )p.imgData.repeat, ( textureUsage_t )p.imgData.usage, ( cubeFiles_t )p.imgData.cubeMap );
numLoaded++;
}
}
//fileSystem->StopPreload();
int end = Sys_Milliseconds();
common->Printf( "%05d images preloaded ( or were already loaded ) in %5.1f seconds\n", numLoaded, ( end - start ) * 0.001 );
common->Printf( "----------------------------------------\n" );
preloadingMapImages = false;
}
}
/*
===============
idImageManager::LoadLevelImages
===============
*/
int idImageManager::LoadLevelImages( bool pacifier )
{
2012-11-26 18:58:24 +00:00
int loadCount = 0;
for( int i = 0 ; i < images.Num() ; i++ )
{
if( pacifier )
{
2012-11-26 18:58:24 +00:00
common->UpdateLevelLoadPacifier();
2012-11-26 18:58:24 +00:00
}
idImage* image = images[ i ];
if( image->generatorFunction )
{
2012-11-26 18:58:24 +00:00
continue;
}
if( image->levelLoadReferenced && !image->IsLoaded() )
{
2012-11-26 18:58:24 +00:00
loadCount++;
image->ActuallyLoadImage( false );
}
}
return loadCount;
}
/*
===============
idImageManager::EndLevelLoad
===============
*/
void idImageManager::EndLevelLoad()
{
2012-11-26 18:58:24 +00:00
insideLevelLoad = false;
2012-11-26 18:58:24 +00:00
common->Printf( "----- idImageManager::EndLevelLoad -----\n" );
int start = Sys_Milliseconds();
int loadCount = LoadLevelImages( true );
2012-11-26 18:58:24 +00:00
int end = Sys_Milliseconds();
common->Printf( "%5i images loaded in %5.1f seconds\n", loadCount, ( end - start ) * 0.001 );
2012-11-26 18:58:24 +00:00
common->Printf( "----------------------------------------\n" );
//R_ListImages_f( idCmdArgs( "sorted sorted", false ) );
}
/*
===============
idImageManager::StartBuild
===============
*/
void idImageManager::StartBuild()
{
2012-11-26 18:58:24 +00:00
}
/*
===============
idImageManager::FinishBuild
===============
*/
void idImageManager::FinishBuild( bool removeDups )
{
2012-11-26 18:58:24 +00:00
}
/*
===============
idImageManager::PrintMemInfo
===============
*/
void idImageManager::PrintMemInfo( MemInfo_t* mi )
{
2012-11-26 18:58:24 +00:00
int i, j, total = 0;
int* sortIndex;
idFile* f;
2012-11-26 18:58:24 +00:00
f = fileSystem->OpenFileWrite( mi->filebase + "_images.txt" );
if( !f )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
// sort first
sortIndex = new( TAG_IMAGE ) int[images.Num()];
for( i = 0; i < images.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
sortIndex[i] = i;
}
for( i = 0; i < images.Num() - 1; i++ )
{
for( j = i + 1; j < images.Num(); j++ )
{
if( images[sortIndex[i]]->StorageSize() < images[sortIndex[j]]->StorageSize() )
{
2012-11-26 18:58:24 +00:00
int temp = sortIndex[i];
sortIndex[i] = sortIndex[j];
sortIndex[j] = temp;
}
}
}
2012-11-26 18:58:24 +00:00
// print next
for( i = 0; i < images.Num(); i++ )
{
idImage* im = images[sortIndex[i]];
2012-11-26 18:58:24 +00:00
int size;
2012-11-26 18:58:24 +00:00
size = im->StorageSize();
total += size;
2012-11-26 18:58:24 +00:00
f->Printf( "%s %3i %s\n", idStr::FormatNumber( size ).c_str(), im->refCount, im->GetName() );
}
2012-11-26 18:58:24 +00:00
delete [] sortIndex;
mi->imageAssetsTotal = total;
2012-11-26 18:58:24 +00:00
f->Printf( "\nTotal image bytes allocated: %s\n", idStr::FormatNumber( total ).c_str() );
fileSystem->CloseFile( f );
}