2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +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;
|
2012-11-28 15:47:07 +00:00
|
|
|
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>
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void R_ReloadImages_f( const idCmdArgs& args )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bool all = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( args.Argc() == 2 )
|
|
|
|
{
|
|
|
|
if( !idStr::Icmp( args.Argv( 1 ), "all" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
all = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "USAGE: reloadImages <all>\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
globalImages->ReloadImages( all );
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
idImage* image;
|
2012-11-26 18:58:24 +00:00
|
|
|
int size;
|
|
|
|
int index;
|
|
|
|
} sortedImage_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
=======================
|
|
|
|
R_QsortImageSizes
|
|
|
|
|
|
|
|
=======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
=======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
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
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void R_ListImages_f( const idCmdArgs& args )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, partialSize;
|
2012-11-28 15:47:07 +00:00
|
|
|
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;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
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;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( idStr::Icmp( args.Argv( 1 ), "sorted" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
sorted = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( idStr::Icmp( args.Argv( 1 ), "namesort" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
sortByName = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( idStr::Icmp( args.Argv( 1 ), "unloaded" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
unloaded = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( idStr::Icmp( args.Argv( 1 ), "duplicated" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
duplicated = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( idStr::Icmp( args.Argv( 1 ), "oversized" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
sorted = true;
|
|
|
|
overSized = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
failed = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
failed = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( failed )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "usage: listImages [ sorted | namesort | unloaded | duplicated | showOverSized ]\n" );
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
totalSize = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
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 ];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( uncompressedOnly )
|
|
|
|
{
|
|
|
|
if( image->IsCompressed() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( unloaded == image->IsLoaded() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// only print duplicates (from mismatched wrap / clamp, etc)
|
2012-11-28 15:47:07 +00:00
|
|
|
if( duplicated )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int j;
|
2012-11-28 15:47:07 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( j == globalImages->images.Num() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( sorted || sortByName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
sortedArray[count].image = image;
|
|
|
|
sortedArray[count].size = image->StorageSize();
|
|
|
|
sortedArray[count].index = i;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "%4i:", i );
|
|
|
|
image->Print();
|
|
|
|
}
|
|
|
|
totalSize += image->StorageSize();
|
|
|
|
count++;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( sorted || sortByName )
|
|
|
|
{
|
|
|
|
if( sortByName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
qsort( sortedArray, count, sizeof( sortedImage_t ), R_QsortImageName );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
qsort( sortedArray, count, sizeof( sortedImage_t ), R_QsortImageSizes );
|
|
|
|
}
|
|
|
|
partialSize = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
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();
|
2012-11-28 15:47:07 +00:00
|
|
|
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-28 15:47:07 +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() );
|
2012-11-28 15:47:07 +00:00
|
|
|
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.
|
|
|
|
==============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int hash = idStr( name ).FileNameHash();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idImage* image = new( TAG_IMAGE ) idImage( name );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
imageHash.Add( hash, images.Append( image ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
AllocStandaloneImage
|
|
|
|
|
|
|
|
Allocates an idImage,does not add it to the list or hash chain
|
|
|
|
|
|
|
|
==============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
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.
|
|
|
|
==================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// see if the image already exists
|
|
|
|
int hash = name.FileNameHash();
|
2012-11-28 15:47:07 +00:00
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// create the image and issue the callback
|
2012-11-28 15:47:07 +00:00
|
|
|
idImage* image = AllocImage( name );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
image->generatorFunction = generatorFunction;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GetImageWithParameters
|
|
|
|
==============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmpn( _name, "fonts", 5 ) == 0 || idStr::Icmpn( _name, "newfonts", 8 ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
usage = TD_FONT;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
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();
|
2012-11-28 15:47:07 +00:00
|
|
|
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
|
2012-11-28 15:47:07 +00:00
|
|
|
if( name[0] == '_' )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return image;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
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 );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
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.
|
|
|
|
==============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
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
|
|
|
|
2012-11-28 15:47:07 +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-28 15:47:07 +00:00
|
|
|
if( idStr::Icmpn( _name, "fonts", 5 ) == 0 || idStr::Icmpn( _name, "newfonts", 8 ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
usage = TD_FONT;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmpn( _name, "lights", 6 ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
usage = TD_LIGHT;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
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();
|
2012-11-28 15:47:07 +00:00
|
|
|
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
|
2012-11-28 15:47:07 +00:00
|
|
|
if( name[0] == '_' )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return image;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
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 );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
image->usage = usage;
|
|
|
|
image->levelLoadReferenced = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//
|
|
|
|
// create a new image
|
|
|
|
//
|
2012-11-28 15:47:07 +00:00
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
image->levelLoadReferenced = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// load it if we aren't in a level preload
|
2012-11-28 15:47:07 +00:00
|
|
|
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() );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
declManager->MediaPrint( "%s\n", image->GetName() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idImageManager::ScratchImage
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
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" );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( imgOpts == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::FatalError( "idImageManager::ScratchImage called with NULL imgOpts" );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr name = _name;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
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();
|
2012-11-28 15:47:07 +00:00
|
|
|
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
|
2012-11-28 15:47:07 +00:00
|
|
|
if( name[0] == '_' )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return image;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
image->usage = usage;
|
|
|
|
image->levelLoadReferenced = true;
|
|
|
|
image->referencedOutsideLevelLoad = true;
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
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
|
2012-11-28 15:47:07 +00:00
|
|
|
if( imgOpts->textureType == TT_CUBIC && repeat != TR_CLAMP )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
repeat = TR_CLAMP;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//
|
|
|
|
// create a new image
|
|
|
|
//
|
|
|
|
idImage* newImage = AllocImage( name );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( newImage != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
newImage->AllocImage( *imgOpts, filter, repeat );
|
|
|
|
}
|
|
|
|
return newImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idImageManager::GetImage
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idImage* idImageManager::GetImage( const char* _name ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +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-28 15:47:07 +00:00
|
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//
|
|
|
|
// look in loaded images
|
|
|
|
//
|
|
|
|
int hash = name.FileNameHash();
|
2012-11-28 15:47:07 +00:00
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
PurgeAllImages
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idImageManager::PurgeAllImages()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
idImage* image;
|
|
|
|
|
|
|
|
for( i = 0; i < images.Num() ; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
image = images[i];
|
|
|
|
image->PurgeImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
ReloadImages
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
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
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr baseName = args.Argv( 1 );
|
|
|
|
common->SetRefreshOnPrint( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( int frameNum = 1 ; frameNum < 10000 ; frameNum++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
char filename[MAX_IMAGE_NAME];
|
2012-11-28 15:47:07 +00:00
|
|
|
byte* pics[6];
|
2012-11-26 18:58:24 +00:00
|
|
|
int width = 0, height = 0;
|
|
|
|
int side;
|
2012-11-28 15:47:07 +00:00
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "reading %s\n", filename );
|
|
|
|
R_LoadImage( filename, &pics[side], &width, &height, NULL, true );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !pics[side] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "not found.\n" );
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// convert from "camera" images to native cube map images
|
2012-11-28 15:47:07 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +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;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "writing %s\n", filename );
|
2012-11-28 15:47:07 +00:00
|
|
|
R_WriteTGA( filename, combined, width, height * 6 );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
common->SetRefreshOnPrint( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
UnbindAll
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idImageManager::UnbindAll()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int oldTMU = backEnd.glState.currenttmu;
|
2012-11-28 15:47:07 +00:00
|
|
|
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
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idImageManager::BindNull()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
RENDERLOG_PRINTF( "BindNull()\n" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Init
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idImageManager::Init()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
images.Resize( 1024, 1024 );
|
|
|
|
imageHash.ResizeIndex( 1024 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
CreateIntrinsicImages();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// should forceLoadImages be here?
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Shutdown
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idImageManager::Shutdown()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
images.DeleteContents( true );
|
|
|
|
imageHash.Clear();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
idImageManager::BeginLevelLoad
|
|
|
|
Frees all images used by the previous level
|
|
|
|
====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idImageManager::BeginLevelLoad()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
insideLevelLoad = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
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
|
2012-11-28 15:47:07 +00:00
|
|
|
if( image->generatorFunction )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !image->referencedOutsideLevelLoad && image->IsLoaded() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
image->PurgeImage();
|
|
|
|
//idLib::Printf( "purging %s\n", image->GetName() );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//idLib::Printf( "not purging %s\n", image->GetName() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
image->levelLoadReferenced = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
idImageManager::ExcludePreloadImage
|
|
|
|
====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idImageManager::ExcludePreloadImage( const char* name )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStrStatic< MAX_OSPATH > imgName = name;
|
|
|
|
imgName.ToLower();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( imgName.Find( "newfonts/", false ) >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( imgName.Find( "generated/swf/", false ) >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( imgName.Find( "/loadscreens/", false ) >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
idImageManager::Preload
|
|
|
|
====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//fileSystem->StartPreload( preloadImageFiles );
|
2012-11-28 15:47:07 +00:00
|
|
|
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
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idImageManager::LoadLevelImages( bool pacifier )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int loadCount = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0 ; i < images.Num() ; i++ )
|
|
|
|
{
|
|
|
|
if( pacifier )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->UpdateLevelLoadPacifier();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idImage* image = images[ i ];
|
|
|
|
if( image->generatorFunction )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( image->levelLoadReferenced && !image->IsLoaded() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
loadCount++;
|
|
|
|
image->ActuallyLoadImage( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return loadCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idImageManager::EndLevelLoad
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idImageManager::EndLevelLoad()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
insideLevelLoad = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "----- idImageManager::EndLevelLoad -----\n" );
|
|
|
|
int start = Sys_Milliseconds();
|
|
|
|
int loadCount = LoadLevelImages( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int end = Sys_Milliseconds();
|
2012-11-28 15:47:07 +00:00
|
|
|
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
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idImageManager::StartBuild()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idImageManager::FinishBuild
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idImageManager::FinishBuild( bool removeDups )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idImageManager::PrintMemInfo
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idImageManager::PrintMemInfo( MemInfo_t* mi )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, j, total = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
int* sortIndex;
|
|
|
|
idFile* f;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
f = fileSystem->OpenFileWrite( mi->filebase + "_images.txt" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// sort first
|
2012-11-28 15:47:07 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// print next
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < images.Num(); i++ )
|
|
|
|
{
|
|
|
|
idImage* im = images[sortIndex[i]];
|
2012-11-26 18:58:24 +00:00
|
|
|
int size;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
size = im->StorageSize();
|
|
|
|
total += size;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
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-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
delete [] sortIndex;
|
|
|
|
mi->imageAssetsTotal = total;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
f->Printf( "\nTotal image bytes allocated: %s\n", idStr::FormatNumber( total ).c_str() );
|
|
|
|
fileSystem->CloseFile( f );
|
|
|
|
}
|