doom3-bfg/neo/renderer/Image_load.cpp

820 lines
19 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"
/*
================
BitsForFormat
================
*/
int BitsForFormat( textureFormat_t format )
{
switch( format )
{
case FMT_NONE:
return 0;
case FMT_RGBA8:
return 32;
case FMT_XRGB8:
return 32;
case FMT_RGB565:
return 16;
case FMT_L8A8:
return 16;
case FMT_ALPHA:
return 8;
case FMT_LUM8:
return 8;
case FMT_INT8:
return 8;
case FMT_DXT1:
return 4;
case FMT_DXT5:
return 8;
case FMT_DEPTH:
return 32;
case FMT_X16:
return 16;
case FMT_Y16_X16:
return 32;
2012-11-26 18:58:24 +00:00
default:
assert( 0 );
return 0;
}
}
/*
========================
idImage::DeriveOpts
========================
*/
ID_INLINE void idImage::DeriveOpts()
{
2012-11-26 18:58:24 +00:00
if( opts.format == FMT_NONE )
{
2012-11-26 18:58:24 +00:00
opts.colorFormat = CFM_DEFAULT;
switch( usage )
{
2012-11-26 18:58:24 +00:00
case TD_COVERAGE:
opts.format = FMT_DXT1;
opts.colorFormat = CFM_GREEN_ALPHA;
break;
case TD_DEPTH:
opts.format = FMT_DEPTH;
break;
case TD_DIFFUSE:
2012-11-26 18:58:24 +00:00
// TD_DIFFUSE gets only set to when its a diffuse texture for an interaction
opts.gammaMips = true;
opts.format = FMT_DXT5;
opts.colorFormat = CFM_YCOCG_DXT5;
break;
case TD_SPECULAR:
opts.gammaMips = true;
opts.format = FMT_DXT1;
opts.colorFormat = CFM_DEFAULT;
break;
case TD_DEFAULT:
opts.gammaMips = true;
opts.format = FMT_DXT5;
opts.colorFormat = CFM_DEFAULT;
break;
case TD_BUMP:
opts.format = FMT_DXT5;
opts.colorFormat = CFM_NORMAL_DXT5;
break;
case TD_FONT:
opts.format = FMT_DXT1;
opts.colorFormat = CFM_GREEN_ALPHA;
opts.numLevels = 4; // We only support 4 levels because we align to 16 in the exporter
opts.gammaMips = true;
break;
case TD_LIGHT:
opts.format = FMT_RGB565;
opts.gammaMips = true;
break;
case TD_LOOKUP_TABLE_MONO:
opts.format = FMT_INT8;
break;
case TD_LOOKUP_TABLE_ALPHA:
opts.format = FMT_ALPHA;
break;
case TD_LOOKUP_TABLE_RGB1:
case TD_LOOKUP_TABLE_RGBA:
opts.format = FMT_RGBA8;
break;
default:
assert( false );
opts.format = FMT_RGBA8;
}
}
if( opts.numLevels == 0 )
{
2012-11-26 18:58:24 +00:00
opts.numLevels = 1;
if( filter == TF_LINEAR || filter == TF_NEAREST )
{
2012-11-26 18:58:24 +00:00
// don't create mip maps if we aren't going to be using them
}
else
{
2012-11-26 18:58:24 +00:00
int temp_width = opts.width;
int temp_height = opts.height;
while( temp_width > 1 || temp_height > 1 )
{
2012-11-26 18:58:24 +00:00
temp_width >>= 1;
temp_height >>= 1;
if( ( opts.format == FMT_DXT1 || opts.format == FMT_DXT5 ) &&
( ( temp_width & 0x3 ) != 0 || ( temp_height & 0x3 ) != 0 ) )
{
break;
2012-11-26 18:58:24 +00:00
}
opts.numLevels++;
}
}
}
}
/*
========================
idImage::AllocImage
========================
*/
void idImage::AllocImage( const idImageOpts& imgOpts, textureFilter_t tf, textureRepeat_t tr )
{
2012-11-26 18:58:24 +00:00
filter = tf;
repeat = tr;
opts = imgOpts;
DeriveOpts();
AllocImage();
}
/*
================
GenerateImage
================
*/
void idImage::GenerateImage( const byte* pic, int width, int height, textureFilter_t filterParm, textureRepeat_t repeatParm, textureUsage_t usageParm )
{
2012-11-26 18:58:24 +00:00
PurgeImage();
2012-11-26 18:58:24 +00:00
filter = filterParm;
repeat = repeatParm;
usage = usageParm;
cubeFiles = CF_2D;
2012-11-26 18:58:24 +00:00
opts.textureType = TT_2D;
opts.width = width;
opts.height = height;
opts.numLevels = 0;
DeriveOpts();
2012-11-26 18:58:24 +00:00
// if we don't have a rendering context, just return after we
// have filled in the parms. We must have the values set, or
// an image match from a shader before the render starts would miss
// the generated texture
if( !R_IsInitialized() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
idBinaryImage im( GetName() );
im.Load2DFromMemory( width, height, pic, opts.numLevels, opts.format, opts.colorFormat, opts.gammaMips );
2012-11-26 18:58:24 +00:00
AllocImage();
for( int i = 0; i < im.NumImages(); i++ )
{
const bimageImage_t& img = im.GetImageHeader( i );
const byte* data = im.GetImageData( i );
2012-11-26 18:58:24 +00:00
SubImageUpload( img.level, 0, 0, img.destZ, img.width, img.height, data );
}
}
/*
====================
GenerateCubeImage
Non-square cube sides are not allowed
====================
*/
void idImage::GenerateCubeImage( const byte* pic[6], int size, textureFilter_t filterParm, textureUsage_t usageParm )
{
2012-11-26 18:58:24 +00:00
PurgeImage();
2012-11-26 18:58:24 +00:00
filter = filterParm;
repeat = TR_CLAMP;
usage = usageParm;
cubeFiles = CF_NATIVE;
2012-11-26 18:58:24 +00:00
opts.textureType = TT_CUBIC;
opts.width = size;
opts.height = size;
opts.numLevels = 0;
DeriveOpts();
2012-11-26 18:58:24 +00:00
// if we don't have a rendering context, just return after we
// have filled in the parms. We must have the values set, or
// an image match from a shader before the render starts would miss
// the generated texture
if( !R_IsInitialized() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
idBinaryImage im( GetName() );
im.LoadCubeFromMemory( size, pic, opts.numLevels, opts.format, opts.gammaMips );
2012-11-26 18:58:24 +00:00
AllocImage();
for( int i = 0; i < im.NumImages(); i++ )
{
const bimageImage_t& img = im.GetImageHeader( i );
const byte* data = im.GetImageData( i );
2012-11-26 18:58:24 +00:00
SubImageUpload( img.level, 0, 0, img.destZ, img.width, img.height, data );
}
}
/*
===============
GetGeneratedName
name contains GetName() upon entry
===============
*/
void idImage::GetGeneratedName( idStr& _name, const textureUsage_t& _usage, const cubeFiles_t& _cube )
{
2012-11-26 18:58:24 +00:00
idStrStatic< 64 > extension;
2012-11-26 18:58:24 +00:00
_name.ExtractFileExtension( extension );
_name.StripFileExtension();
_name += va( "#__%02d%02d", ( int )_usage, ( int )_cube );
if( extension.Length() > 0 )
{
2012-11-26 18:58:24 +00:00
_name.SetFileExtension( extension );
}
}
/*
===============
ActuallyLoadImage
Absolutely every image goes through this path
On exit, the idImage will have a valid OpenGL texture number that can be bound
===============
*/
void idImage::ActuallyLoadImage( bool fromBackEnd )
{
2012-11-26 18:58:24 +00:00
// if we don't have a rendering context yet, just return
if( !R_IsInitialized() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
// this is the ONLY place generatorFunction will ever be called
if( generatorFunction )
{
2012-11-26 18:58:24 +00:00
generatorFunction( this );
return;
}
if( com_productionMode.GetInteger() != 0 )
{
2012-11-26 18:58:24 +00:00
sourceFileTime = FILE_NOT_FOUND_TIMESTAMP;
if( cubeFiles != CF_2D )
{
2012-11-26 18:58:24 +00:00
opts.textureType = TT_CUBIC;
repeat = TR_CLAMP;
}
}
else
{
if( cubeFiles != CF_2D )
{
2012-11-26 18:58:24 +00:00
opts.textureType = TT_CUBIC;
repeat = TR_CLAMP;
R_LoadCubeImages( GetName(), cubeFiles, NULL, NULL, &sourceFileTime );
}
else
{
2012-11-26 18:58:24 +00:00
opts.textureType = TT_2D;
R_LoadImageProgram( GetName(), NULL, NULL, NULL, &sourceFileTime, &usage );
}
}
2012-11-26 18:58:24 +00:00
// Figure out opts.colorFormat and opts.format so we can make sure the binary image is up to date
DeriveOpts();
2012-11-26 18:58:24 +00:00
idStrStatic< MAX_OSPATH > generatedName = GetName();
GetGeneratedName( generatedName, usage, cubeFiles );
2012-11-26 18:58:24 +00:00
idBinaryImage im( generatedName );
binaryFileTime = im.LoadFromGeneratedFile( sourceFileTime );
2012-11-26 18:58:24 +00:00
// BFHACK, do not want to tweak on buildgame so catch these images here
if( binaryFileTime == FILE_NOT_FOUND_TIMESTAMP && fileSystem->UsingResourceFiles() )
{
2012-11-26 18:58:24 +00:00
int c = 1;
while( c-- > 0 )
{
if( generatedName.Find( "guis/assets/white#__0000", false ) >= 0 )
{
2012-11-26 18:58:24 +00:00
generatedName.Replace( "white#__0000", "white#__0200" );
im.SetName( generatedName );
binaryFileTime = im.LoadFromGeneratedFile( sourceFileTime );
break;
}
if( generatedName.Find( "guis/assets/white#__0100", false ) >= 0 )
{
2012-11-26 18:58:24 +00:00
generatedName.Replace( "white#__0100", "white#__0200" );
im.SetName( generatedName );
binaryFileTime = im.LoadFromGeneratedFile( sourceFileTime );
break;
}
if( generatedName.Find( "textures/black#__0100", false ) >= 0 )
{
2012-11-26 18:58:24 +00:00
generatedName.Replace( "black#__0100", "black#__0200" );
im.SetName( generatedName );
binaryFileTime = im.LoadFromGeneratedFile( sourceFileTime );
break;
}
if( generatedName.Find( "textures/decals/bulletglass1_d#__0100", false ) >= 0 )
{
2012-11-26 18:58:24 +00:00
generatedName.Replace( "bulletglass1_d#__0100", "bulletglass1_d#__0200" );
im.SetName( generatedName );
binaryFileTime = im.LoadFromGeneratedFile( sourceFileTime );
break;
}
if( generatedName.Find( "models/monsters/skeleton/skeleton01_d#__1000", false ) >= 0 )
{
2012-11-26 18:58:24 +00:00
generatedName.Replace( "skeleton01_d#__1000", "skeleton01_d#__0100" );
im.SetName( generatedName );
binaryFileTime = im.LoadFromGeneratedFile( sourceFileTime );
break;
}
}
}
const bimageFile_t& header = im.GetFileHeader();
if( ( fileSystem->InProductionMode() && binaryFileTime != FILE_NOT_FOUND_TIMESTAMP ) || ( ( binaryFileTime != FILE_NOT_FOUND_TIMESTAMP )
&& ( header.colorFormat == opts.colorFormat )
&& ( header.format == opts.format )
&& ( header.textureType == opts.textureType )
) )
{
2012-11-26 18:58:24 +00:00
opts.width = header.width;
opts.height = header.height;
opts.numLevels = header.numLevels;
opts.colorFormat = ( textureColor_t )header.colorFormat;
opts.format = ( textureFormat_t )header.format;
opts.textureType = ( textureType_t )header.textureType;
if( cvarSystem->GetCVarBool( "fs_buildresources" ) )
{
2012-11-26 18:58:24 +00:00
// for resource gathering write this image to the preload file for this map
fileSystem->AddImagePreload( GetName(), filter, repeat, usage, cubeFiles );
}
}
else
{
if( cubeFiles != CF_2D )
{
2012-11-26 18:58:24 +00:00
int size;
byte* pics[6];
if( !R_LoadCubeImages( GetName(), cubeFiles, pics, &size, &sourceFileTime ) || size == 0 )
{
2012-11-26 18:58:24 +00:00
idLib::Warning( "Couldn't load cube image: %s", GetName() );
return;
}
2012-11-26 18:58:24 +00:00
opts.textureType = TT_CUBIC;
repeat = TR_CLAMP;
opts.width = size;
opts.height = size;
opts.numLevels = 0;
DeriveOpts();
im.LoadCubeFromMemory( size, ( const byte** )pics, opts.numLevels, opts.format, opts.gammaMips );
2012-11-26 18:58:24 +00:00
repeat = TR_CLAMP;
for( int i = 0; i < 6; i++ )
{
if( pics[i] )
{
2012-11-26 18:58:24 +00:00
Mem_Free( pics[i] );
}
}
}
else
{
2012-11-26 18:58:24 +00:00
int width, height;
byte* pic;
2012-11-26 18:58:24 +00:00
// load the full specification, and perform any image program calculations
R_LoadImageProgram( GetName(), &pic, &width, &height, &sourceFileTime, &usage );
if( pic == NULL )
{
2012-11-26 18:58:24 +00:00
idLib::Warning( "Couldn't load image: %s : %s", GetName(), generatedName.c_str() );
// create a default so it doesn't get continuously reloaded
opts.width = 8;
opts.height = 8;
opts.numLevels = 1;
DeriveOpts();
AllocImage();
// clear the data so it's not left uninitialized
idTempArray<byte> clear( opts.width * opts.height * 4 );
memset( clear.Ptr(), 0, clear.Size() );
for( int level = 0; level < opts.numLevels; level++ )
{
2012-11-26 18:58:24 +00:00
SubImageUpload( level, 0, 0, 0, opts.width >> level, opts.height >> level, clear.Ptr() );
}
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
opts.width = width;
opts.height = height;
opts.numLevels = 0;
DeriveOpts();
im.Load2DFromMemory( opts.width, opts.height, pic, opts.numLevels, opts.format, opts.colorFormat, opts.gammaMips );
2012-11-26 18:58:24 +00:00
Mem_Free( pic );
}
binaryFileTime = im.WriteGeneratedFile( sourceFileTime );
}
2012-11-26 18:58:24 +00:00
AllocImage();
for( int i = 0; i < im.NumImages(); i++ )
{
const bimageImage_t& img = im.GetImageHeader( i );
const byte* data = im.GetImageData( i );
2012-11-26 18:58:24 +00:00
SubImageUpload( img.level, 0, 0, img.destZ, img.width, img.height, data );
}
}
/*
==============
Bind
Automatically enables 2D mapping or cube mapping if needed
==============
*/
void idImage::Bind()
{
2012-11-26 18:58:24 +00:00
RENDERLOG_PRINTF( "idImage::Bind( %s )\n", GetName() );
2012-11-26 18:58:24 +00:00
// load the image if necessary (FIXME: not SMP safe!)
if( !IsLoaded() )
{
2012-11-26 18:58:24 +00:00
// load the image on demand here, which isn't our normal game operating mode
ActuallyLoadImage( true );
}
2012-11-26 18:58:24 +00:00
const int texUnit = backEnd.glState.currenttmu;
tmu_t* tmu = &backEnd.glState.tmu[texUnit];
2012-11-26 18:58:24 +00:00
// bind the texture
if( opts.textureType == TT_2D )
{
if( tmu->current2DMap != texnum )
{
2012-11-26 18:58:24 +00:00
tmu->current2DMap = texnum;
qglBindMultiTextureEXT( GL_TEXTURE0_ARB + texUnit, GL_TEXTURE_2D, texnum );
}
}
else if( opts.textureType == TT_CUBIC )
{
if( tmu->currentCubeMap != texnum )
{
2012-11-26 18:58:24 +00:00
tmu->currentCubeMap = texnum;
qglBindMultiTextureEXT( GL_TEXTURE0_ARB + texUnit, GL_TEXTURE_CUBE_MAP_EXT, texnum );
}
}
2012-11-26 18:58:24 +00:00
}
/*
================
MakePowerOfTwo
================
*/
int MakePowerOfTwo( int num )
{
2012-11-26 18:58:24 +00:00
int pot;
for( pot = 1; pot < num; pot <<= 1 )
{
2012-11-26 18:58:24 +00:00
}
return pot;
}
/*
====================
CopyFramebuffer
====================
*/
void idImage::CopyFramebuffer( int x, int y, int imageWidth, int imageHeight )
{
2012-11-26 18:58:24 +00:00
qglBindTexture( ( opts.textureType == TT_CUBIC ) ? GL_TEXTURE_CUBE_MAP_EXT : GL_TEXTURE_2D, texnum );
2012-11-26 18:58:24 +00:00
qglReadBuffer( GL_BACK );
2012-11-26 18:58:24 +00:00
opts.width = imageWidth;
opts.height = imageHeight;
qglCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, x, y, imageWidth, imageHeight, 0 );
2012-11-26 18:58:24 +00:00
// these shouldn't be necessary if the image was initialized properly
qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
2012-11-26 18:58:24 +00:00
qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
2012-11-26 18:58:24 +00:00
backEnd.pc.c_copyFrameBuffer++;
}
/*
====================
CopyDepthbuffer
====================
*/
void idImage::CopyDepthbuffer( int x, int y, int imageWidth, int imageHeight )
{
2012-11-26 18:58:24 +00:00
qglBindTexture( ( opts.textureType == TT_CUBIC ) ? GL_TEXTURE_CUBE_MAP_EXT : GL_TEXTURE_2D, texnum );
2012-11-26 18:58:24 +00:00
opts.width = imageWidth;
opts.height = imageHeight;
qglCopyTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, x, y, imageWidth, imageHeight, 0 );
2012-11-26 18:58:24 +00:00
backEnd.pc.c_copyFrameBuffer++;
}
/*
=============
RB_UploadScratchImage
if rows = cols * 6, assume it is a cube map animation
=============
*/
void idImage::UploadScratch( const byte* data, int cols, int rows )
{
2012-11-26 18:58:24 +00:00
// if rows = cols * 6, assume it is a cube map animation
if( rows == cols * 6 )
{
2012-11-26 18:58:24 +00:00
rows /= 6;
const byte* pic[6];
for( int i = 0; i < 6; i++ )
{
2012-11-26 18:58:24 +00:00
pic[i] = data + cols * rows * 4 * i;
}
if( opts.textureType != TT_CUBIC || usage != TD_LOOKUP_TABLE_RGBA )
{
2012-11-26 18:58:24 +00:00
GenerateCubeImage( pic, cols, TF_LINEAR, TD_LOOKUP_TABLE_RGBA );
return;
}
if( opts.width != cols || opts.height != rows )
{
2012-11-26 18:58:24 +00:00
opts.width = cols;
opts.height = rows;
AllocImage();
}
SetSamplerState( TF_LINEAR, TR_CLAMP );
for( int i = 0; i < 6; i++ )
{
2012-11-26 18:58:24 +00:00
SubImageUpload( 0, 0, 0, i, opts.width, opts.height, pic[i] );
}
}
else
{
if( opts.textureType != TT_2D || usage != TD_LOOKUP_TABLE_RGBA )
{
2012-11-26 18:58:24 +00:00
GenerateImage( data, cols, rows, TF_LINEAR, TR_REPEAT, TD_LOOKUP_TABLE_RGBA );
return;
}
if( opts.width != cols || opts.height != rows )
{
2012-11-26 18:58:24 +00:00
opts.width = cols;
opts.height = rows;
AllocImage();
}
SetSamplerState( TF_LINEAR, TR_REPEAT );
SubImageUpload( 0, 0, 0, 0, opts.width, opts.height, data );
}
}
/*
==================
StorageSize
==================
*/
int idImage::StorageSize() const
{
2012-11-26 18:58:24 +00:00
if( !IsLoaded() )
{
2012-11-26 18:58:24 +00:00
return 0;
}
int baseSize = opts.width * opts.height;
if( opts.numLevels > 1 )
{
2012-11-26 18:58:24 +00:00
baseSize *= 4;
baseSize /= 3;
}
baseSize *= BitsForFormat( opts.format );
baseSize /= 8;
return baseSize;
}
/*
==================
Print
==================
*/
void idImage::Print() const
{
if( generatorFunction )
{
2012-11-26 18:58:24 +00:00
common->Printf( "F" );
}
else
{
2012-11-26 18:58:24 +00:00
common->Printf( " " );
}
switch( opts.textureType )
{
2012-11-26 18:58:24 +00:00
case TT_2D:
common->Printf( " " );
break;
case TT_CUBIC:
common->Printf( "C" );
break;
default:
common->Printf( "<BAD TYPE:%i>", opts.textureType );
break;
}
2012-11-26 18:58:24 +00:00
common->Printf( "%4i %4i ", opts.width, opts.height );
switch( opts.format )
{
2012-11-26 18:58:24 +00:00
#define NAME_FORMAT( x ) case FMT_##x: common->Printf( "%-6s ", #x ); break;
NAME_FORMAT( NONE );
NAME_FORMAT( RGBA8 );
NAME_FORMAT( XRGB8 );
NAME_FORMAT( RGB565 );
NAME_FORMAT( L8A8 );
NAME_FORMAT( ALPHA );
NAME_FORMAT( LUM8 );
NAME_FORMAT( INT8 );
NAME_FORMAT( DXT1 );
NAME_FORMAT( DXT5 );
NAME_FORMAT( DEPTH );
NAME_FORMAT( X16 );
NAME_FORMAT( Y16_X16 );
2012-11-26 18:58:24 +00:00
default:
common->Printf( "<%3i>", opts.format );
break;
}
switch( filter )
{
2012-11-26 18:58:24 +00:00
case TF_DEFAULT:
common->Printf( "mip " );
break;
case TF_LINEAR:
common->Printf( "linr " );
break;
case TF_NEAREST:
common->Printf( "nrst " );
break;
default:
common->Printf( "<BAD FILTER:%i>", filter );
break;
}
switch( repeat )
{
2012-11-26 18:58:24 +00:00
case TR_REPEAT:
common->Printf( "rept " );
break;
case TR_CLAMP_TO_ZERO:
common->Printf( "zero " );
break;
case TR_CLAMP_TO_ZERO_ALPHA:
common->Printf( "azro " );
break;
case TR_CLAMP:
common->Printf( "clmp " );
break;
default:
common->Printf( "<BAD REPEAT:%i>", repeat );
break;
}
2012-11-26 18:58:24 +00:00
common->Printf( "%4ik ", StorageSize() / 1024 );
2012-11-26 18:58:24 +00:00
common->Printf( " %s\n", GetName() );
}
/*
===============
idImage::Reload
===============
*/
void idImage::Reload( bool force )
{
2012-11-26 18:58:24 +00:00
// always regenerate functional images
if( generatorFunction )
{
2012-11-26 18:58:24 +00:00
common->DPrintf( "regenerating %s.\n", GetName() );
generatorFunction( this );
return;
}
2012-11-26 18:58:24 +00:00
// check file times
if( !force )
{
2012-11-26 18:58:24 +00:00
ID_TIME_T current;
if( cubeFiles != CF_2D )
{
2012-11-26 18:58:24 +00:00
R_LoadCubeImages( imgName, cubeFiles, NULL, NULL, &current );
}
else
{
2012-11-26 18:58:24 +00:00
// get the current values
R_LoadImageProgram( imgName, NULL, NULL, NULL, &current );
}
if( current <= sourceFileTime )
{
2012-11-26 18:58:24 +00:00
return;
}
}
2012-11-26 18:58:24 +00:00
common->DPrintf( "reloading %s.\n", GetName() );
2012-11-26 18:58:24 +00:00
PurgeImage();
2012-11-26 18:58:24 +00:00
// Load is from the front end, so the back end must be synced
ActuallyLoadImage( false );
}
/*
========================
idImage::SetSamplerState
========================
*/
void idImage::SetSamplerState( textureFilter_t tf, textureRepeat_t tr )
{
if( tf == filter && tr == repeat )
{
2012-11-26 18:58:24 +00:00
return;
}
filter = tf;
repeat = tr;
qglBindTexture( ( opts.textureType == TT_CUBIC ) ? GL_TEXTURE_CUBE_MAP_EXT : GL_TEXTURE_2D, texnum );
SetTexParameters();
}