Skip to content

Commit

Permalink
renderer: add r_imageFitScreen cvar
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed May 29, 2024
1 parent 00a5a8f commit c567434
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/engine/renderer/InternalImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int R_GetImageCustomScalingStep( const image_t *image, const imageParams_t &imag

int scalingStep = 0;

// Scale down the image size until it's not smaller than screen.
// Scale down the image size according to the screen size.
if ( image->bits & IF_FITSCREEN )
{
int largerSide = std::max( glConfig.vidWidth, glConfig.vidHeight );
Expand All @@ -123,8 +123,13 @@ int R_GetImageCustomScalingStep( const image_t *image, const imageParams_t &imag
scalingStep++;
}

// We need the larger image size before it becomes smaller than screen.
if ( scaledDimension != largerSide )
/* With r_imageFitScreen == 1, we need the larger image size before
it becomes smaller than screen.
With r_imageFitScreen == 2 the image is never larger than screen, as
we allow the larger size that is not larger than screen, it can be the
larger size smaller than screen. */
if ( scaledDimension != largerSide && r_imageFitScreen.Get() != 2 )
{
scaledDimension <<= 1;
scalingStep--;
Expand Down
8 changes: 8 additions & 0 deletions src/engine/renderer/tr_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,14 @@ void R_UploadImage( const byte **dataArray, int numLayers, int numMips, image_t

int scaledWidth = image->width;
int scaledHeight = image->height;

// If r_imageFitScreen is disabled, use nopicmip instead.
if ( ( image->bits & IF_FITSCREEN ) && !r_imageFitScreen.Get() )
{
image->bits &= ~IF_FITSCREEN;
image->bits |= IF_NOPICMIP;
}

int customScalingStep = R_GetImageCustomScalingStep( image, imageParams );
R_DownscaleImageDimensions( customScalingStep, &scaledWidth, &scaledHeight, &dataArray, numLayers, &numMips );

Expand Down
2 changes: 2 additions & 0 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
cvar_t *r_ignoreMaterialMinDimension;
cvar_t *r_ignoreMaterialMaxDimension;
cvar_t *r_replaceMaterialMinDimensionIfPresentWithMaxDimension;
Cvar::Range<Cvar::Cvar<int>> r_imageFitScreen("r_imageFitScreen", "downscale “fitscreen” images according to screen size: 0: do not downscale, 1: downscale as much as possible without being smaller than screen size, 2: downscale to never be larger then screen size", Cvar::NONE, 1, 0, 2);
cvar_t *r_finish;
cvar_t *r_clear;
cvar_t *r_textureMode;
Expand Down Expand Up @@ -1095,6 +1096,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
r_ignoreMaterialMaxDimension = Cvar_Get( "r_ignoreMaterialMaxDimension", "0", CVAR_LATCH | CVAR_ARCHIVE );
r_replaceMaterialMinDimensionIfPresentWithMaxDimension
= Cvar_Get( "r_replaceMaterialMinDimensionIfPresentWithMaxDimension", "0", CVAR_LATCH | CVAR_ARCHIVE );
Cvar::Latch(r_imageFitScreen);
r_colorbits = Cvar_Get( "r_colorbits", "0", CVAR_LATCH );
r_mode = Cvar_Get( "r_mode", "-2", CVAR_LATCH | CVAR_ARCHIVE );
r_customwidth = Cvar_Get( "r_customwidth", "1600", CVAR_LATCH | CVAR_ARCHIVE );
Expand Down
1 change: 1 addition & 0 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -2911,6 +2911,7 @@ enum class dynamicLightRenderer_t { LEGACY, TILED };
extern cvar_t *r_ignoreMaterialMinDimension;
extern cvar_t *r_ignoreMaterialMaxDimension;
extern cvar_t *r_replaceMaterialMinDimensionIfPresentWithMaxDimension;
extern Cvar::Range<Cvar::Cvar<int>> r_imageFitScreen;
extern cvar_t *r_finish;
extern cvar_t *r_drawBuffer;
extern cvar_t *r_textureMode;
Expand Down

0 comments on commit c567434

Please sign in to comment.