Index: src/game_config.h =================================================================== --- src/game_config.h (revision 197) +++ src/game_config.h (working copy) @@ -198,6 +198,10 @@ PROTO_PARAM_BOOL( disable_background ); +PROTO_PARAM_INT( max_texture_size ); + +PROTO_PARAM_INT( compressed_texture_size ); + PROTO_PARAM_STRING( ui_language ); Index: src/game_config.cpp =================================================================== --- src/game_config.cpp (revision 197) +++ src/game_config.cpp (working copy) @@ -472,6 +472,8 @@ struct param ui_language; struct param disable_videomode_autodetection; struct param disable_background; + struct param max_texture_size; + struct param compressed_texture_size; }; static struct params Params; @@ -831,7 +833,23 @@ disable_background, false, "# Set this to completely remove the background (skybox)\n" "# This option would improve the performance." ); + + INIT_PARAM_INT( + max_texture_size, 0, + "# Maximum texture size, larger textures will be scaled down\n" + "# to this size. This may improve performance if you are limited\n" + "# by graphics memory capacity or bandwidth, at the expense of\n" + "# lower image quality.\n" + "# Values must be powers of 2, e.g. 512 or 256.\n" + "# The default value of 0 means the graphics card maximum\n" + "# texture size will be the limit." ); + INIT_PARAM_INT( + compressed_texture_size, 0, + "# Try to use texture compression for textures this size or larger.\n" + "# May improve performance, at the expense of reduced image quality.\n" + "# Default value of 0 disables texture compression." ); + INIT_PARAM_STRING( ui_language, "en_GB" , "# set the language for the ui" @@ -921,6 +939,8 @@ FN_PARAM_BOOL( disable_collision_detection ) FN_PARAM_BOOL( disable_videomode_autodetection ) FN_PARAM_BOOL( disable_background ) +FN_PARAM_INT( max_texture_size ) +FN_PARAM_INT( compressed_texture_size ) FN_PARAM_STRING( ui_language ) Index: src/textures.cpp =================================================================== --- src/textures.cpp (revision 197) +++ src/textures.cpp (working copy) @@ -78,6 +78,8 @@ texture_node_t *tex; int max_texture_size; + GLint internal_format; + const GLubyte *exts; print_debug(DEBUG_TEXTURE, "Loading texture %s from file: %s", @@ -120,6 +122,12 @@ /* Check if we need to scale image */ glGetIntegerv( GL_MAX_TEXTURE_SIZE, (GLint*) &max_texture_size ); + + if ( getparam_max_texture_size() > 0 ) + { + max_texture_size = std::min( max_texture_size, getparam_max_texture_size() ); + } + if ( texImage->width > max_texture_size || texImage->height > max_texture_size ) { @@ -129,9 +137,13 @@ check_assertion( newdata != NULL, "out of memory" ); - print_debug( DEBUG_TEXTURE, "Texture `%s' too large -- scaling to " - "maximum allowed size", - filename ); + print_debug( DEBUG_TEXTURE, "Texture `%s' %dx%d -- scaling to " + "%dx%d", + filename, + texImage->width, + texImage->height, + max_texture_size, + max_texture_size ); /* In the case of large- or small-aspect ratio textures, this could end up using *more* space... oh well. */ @@ -149,7 +161,49 @@ texImage->height = max_texture_size; } - gluBuild2DMipmaps( GL_TEXTURE_2D, texImage->depth, texImage->width, + max_texture_size = getparam_compressed_texture_size(); + if ( (max_texture_size > 0) && + (texImage->width >= max_texture_size || + texImage->height >= max_texture_size) ) + { + exts = glGetString( GL_EXTENSIONS ); + + /* you need to have libtxc_dxtn for S3TC with mesa */ + if ( gluCheckExtension( (const GLubyte*)"GL_EXT_texture_compression_s3tc", exts ) == GL_TRUE ) + { + print_debug( DEBUG_TEXTURE, + "Using S3TC for %s", + filename ); + internal_format = texImage->depth == 3 ? GL_COMPRESSED_RGB_S3TC_DXT1_EXT : GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + } + else if ( gluCheckExtension( (const GLubyte*)"GL_3DFX_texture_compression_FXT1", exts ) == GL_TRUE ) + { + print_debug( DEBUG_TEXTURE, + "Using 3DFX FXT1 for %s", + filename ); + internal_format = texImage->depth == 3 ? GL_COMPRESSED_RGB_FXT1_3DFX : GL_COMPRESSED_RGBA_FXT1_3DFX; + } + else if ( gluCheckExtension( (const GLubyte*)"GL_ARB_texture_compression", exts ) == GL_TRUE ) + { + /* this probably won't actually do any compression */ + print_debug( DEBUG_TEXTURE, + "Trying ARB texture compression for %s", + filename ); + internal_format = texImage->depth == 3 ? GL_COMPRESSED_RGB_ARB : GL_COMPRESSED_RGBA_ARB; + } + else + { + print_debug( DEBUG_TEXTURE, + "Could not find any compressed texture format for %s", + filename ); + internal_format = texImage->depth; + } + } + else + { + internal_format = texImage->depth; + } + gluBuild2DMipmaps( GL_TEXTURE_2D, internal_format, texImage->width, texImage->height, texImage->depth == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, texImage->data );