doom3-bfg/neo/renderer/Image.h

708 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.
Copyright (C) 2013-2021 Robert Beckebans
Copyright (C) 2016-2017 Dustin Land
2022-02-21 15:29:53 +00:00
Copyright (C) 2022 Stephen Pridham
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.
===========================================================================
*/
2022-02-21 15:29:53 +00:00
#ifndef IMAGE_H_
#define IMAGE_H_
enum textureType_t
{
TT_DISABLED,
TT_2D,
TT_CUBIC,
// RB begin
TT_2D_ARRAY,
2022-02-21 15:29:53 +00:00
TT_2D_MULTISAMPLE,
// RB end
};
/*
================================================
The internal *Texture Format Types*, ::textureFormat_t, are:
================================================
*/
enum textureFormat_t
{
FMT_NONE,
2019-11-11 19:27:44 +00:00
//------------------------
// Standard color image formats
//------------------------
2019-11-11 19:27:44 +00:00
FMT_RGBA8, // 32 bpp
FMT_XRGB8, // 32 bpp
2019-11-11 19:27:44 +00:00
//------------------------
// Alpha channel only
//------------------------
2019-11-11 19:27:44 +00:00
// Alpha ends up being the same as L8A8 in our current implementation, because straight
// alpha gives 0 for color, but we want 1.
FMT_ALPHA,
2019-11-11 19:27:44 +00:00
//------------------------
// Luminance replicates the value across RGB with a constant A of 255
// Intensity replicates the value across RGBA
//------------------------
2019-11-11 19:27:44 +00:00
FMT_L8A8, // 16 bpp
FMT_LUM8, // 8 bpp
FMT_INT8, // 8 bpp
2019-11-11 19:27:44 +00:00
//------------------------
// Compressed texture formats
//------------------------
2019-11-11 19:27:44 +00:00
FMT_DXT1, // 4 bpp
FMT_DXT5, // 8 bpp
2019-11-11 19:27:44 +00:00
//------------------------
// Depth buffer formats
//------------------------
2019-11-11 19:27:44 +00:00
FMT_DEPTH, // 24 bpp
2019-11-11 19:27:44 +00:00
//------------------------
//
//------------------------
2019-11-11 19:27:44 +00:00
FMT_X16, // 16 bpp
FMT_Y16_X16, // 32 bpp
FMT_RGB565, // 16 bpp
2019-11-11 19:27:44 +00:00
2022-04-12 16:15:48 +00:00
// RB: don't change above for .bimage compatibility up until RBDOOM-3-BFG 1.1
FMT_ETC1_RGB8_OES, // 4 bpp
FMT_SHADOW_ARRAY, // 32 bpp * 6
FMT_RG16F, // 32 bpp
FMT_RGBA16F, // 64 bpp
FMT_RGBA32F, // 128 bpp
FMT_R32F, // 32 bpp
FMT_R11G11B10F, // 32 bpp
2022-04-12 16:15:48 +00:00
// ^-- used up until RBDOOM-3-BFG 1.3
2022-02-21 15:29:53 +00:00
FMT_R8,
FMT_DEPTH_STENCIL, // 32 bpp
2022-04-12 16:15:48 +00:00
FMT_RGBA16S, // 64 bpp
2022-03-09 19:40:15 +00:00
FMT_SRGB8,
};
int BitsForFormat( textureFormat_t format );
int GetRowPitch( const textureFormat_t& format, int width );
/*
================================================
DXT5 color formats
================================================
*/
enum textureColor_t
{
CFM_DEFAULT, // RGBA
CFM_NORMAL_DXT5, // XY format and use the fast DXT5 compressor
CFM_YCOCG_DXT5, // convert RGBA to CoCg_Y format
CFM_GREEN_ALPHA, // Copy the alpha channel to green
2019-11-11 19:27:44 +00:00
// RB: don't change above for legacy .bimage compatibility
CFM_YCOCG_RGBA8,
// RB end
};
/*
================================================
idImageOpts hold parameters for texture operations.
================================================
*/
class idImageOpts
{
public:
idImageOpts();
2019-11-11 19:27:44 +00:00
bool operator==( const idImageOpts& opts );
2019-11-11 19:27:44 +00:00
//---------------------------------------------------
// these determine the physical memory size and layout
//---------------------------------------------------
2019-11-11 19:27:44 +00:00
textureType_t textureType;
textureFormat_t format;
textureColor_t colorFormat;
uint samples;
int width;
int height; // not needed for cube maps
int numLevels; // if 0, will be 1 for NEAREST / LINEAR filters, otherwise based on size
bool gammaMips; // if true, mips will be generated with gamma correction
bool readback; // 360 specific - cpu reads back from this texture, so allocate with cached memory
2022-02-21 15:29:53 +00:00
bool isRenderTarget;
2022-04-12 16:15:48 +00:00
bool isUAV;
};
/*
========================
idImageOpts::idImageOpts
========================
*/
ID_INLINE idImageOpts::idImageOpts()
{
format = FMT_NONE;
colorFormat = CFM_DEFAULT;
samples = 1;
width = 0;
height = 0;
numLevels = 0;
textureType = TT_2D;
gammaMips = false;
readback = false;
2022-02-21 15:29:53 +00:00
isRenderTarget = false;
2022-04-12 16:15:48 +00:00
isUAV = false;
2022-02-21 15:29:53 +00:00
}
/*
========================
idImageOpts::operator==
========================
*/
ID_INLINE bool idImageOpts::operator==( const idImageOpts& opts )
{
return ( memcmp( this, &opts, sizeof( *this ) ) == 0 );
}
2012-11-26 18:58:24 +00:00
/*
====================================================================
IMAGE
idImage have a one to one correspondance with GL/DX/GCM textures.
No texture is ever used that does not have a corresponding idImage.
====================================================================
*/
static const int MAX_TEXTURE_LEVELS = 14;
// How is this texture used? Determines the storage and color format
typedef enum
{
2012-11-26 18:58:24 +00:00
TD_SPECULAR, // may be compressed, and always zeros the alpha channel
TD_DIFFUSE, // may be compressed
TD_DEFAULT, // generic RGBA texture (particles, etc...)
TD_BUMP, // may be compressed with 8 bit lookup
TD_FONT, // Font image
TD_LIGHT, // Light image
TD_LOOKUP_TABLE_MONO, // Mono lookup table (including alpha)
TD_LOOKUP_TABLE_ALPHA, // Alpha lookup table with a white color channel
TD_LOOKUP_TABLE_RGB1, // RGB lookup table with a solid white alpha
TD_LOOKUP_TABLE_RGBA, // RGBA lookup table
TD_COVERAGE, // coverage map for fill depth pass when YCoCG is used
TD_DEPTH, // depth buffer copy for motion blur
// RB begin
TD_SPECULAR_PBR_RMAO, // may be compressed, and always zeros the alpha channel, linear RGB R = roughness, G = metal, B = ambient occlusion
TD_SPECULAR_PBR_RMAOD, // may be compressed, alpha channel contains displacement map
2016-07-07 01:17:33 +00:00
TD_HIGHQUALITY_CUBE, // motorsep - Uncompressed cubemap texture (RGB colorspace)
TD_LOWQUALITY_CUBE, // motorsep - Compressed cubemap texture (RGB colorspace DXT5)
TD_SHADOW_ARRAY, // 2D depth buffer array for shadow mapping
TD_RG16F,
TD_RGBA16F,
2022-04-12 16:15:48 +00:00
TD_RGBA16S,
TD_RGBA32F,
TD_R32F,
TD_R11G11B10F, // memory efficient HDR RGB format with only 32bpp
// RB end
2022-02-21 15:29:53 +00:00
TD_R8F, // Stephen: Added for ambient occlusion render target.
2022-03-09 19:40:15 +00:00
TD_LDR, // Stephen: Added for SRGB render target when tonemapping.
2022-03-15 10:41:56 +00:00
TD_DEPTH_STENCIL, // depth buffer and stencil buffer
2012-11-26 18:58:24 +00:00
} textureUsage_t;
typedef enum
{
2012-11-26 18:58:24 +00:00
CF_2D, // not a cube map
CF_NATIVE, // _px, _nx, _py, etc, directly sent to GL
CF_CAMERA, // _forward, _back, etc, rotated and flipped as needed before sending to GL
CF_QUAKE1, // _ft, _bk, etc, rotated and flipped as needed before sending to GL
CF_PANORAMA, // TODO latlong encoded HDRI panorama typically used by Substance or Blender
CF_2D_ARRAY, // not a cube map but not a single 2d texture either
2022-02-21 15:29:53 +00:00
CF_2D_PACKED_MIPCHAIN, // usually 2d but can be an octahedron, packed mipmaps into single 2d texture atlas and limited to dim^2
CF_SINGLE, // SP: A single texture cubemap. All six sides in one image.
2012-11-26 18:58:24 +00:00
} cubeFiles_t;
typedef void ( *ImageGeneratorFunction )( idImage* image, nvrhi::ICommandList* commandList );
2022-02-21 15:29:53 +00:00
2012-11-26 18:58:24 +00:00
#include "BinaryImage.h"
#define MAX_IMAGE_NAME 256
class idImage
{
friend class Framebuffer;
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
public:
idImage( const char* name );
2017-09-03 11:56:30 +00:00
~idImage();
2019-11-11 19:27:44 +00:00
const char* GetName() const
{
return imgName;
}
2019-11-11 19:27:44 +00:00
2022-02-21 15:29:53 +00:00
// Makes this image active on the current texture unit.
2012-11-26 18:58:24 +00:00
// automatically enables or disables cube mapping
// May perform file loading if the image was not preloaded.
void Bind();
2019-11-11 19:27:44 +00:00
// RB begin
2022-02-21 15:29:53 +00:00
void GenerateShadowArray( int width, int height, textureFilter_t filter, textureRepeat_t repeat, textureUsage_t usage, nvrhi::ICommandList* commandList );
// RB end
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
void CopyFramebuffer( int x, int y, int width, int height );
void CopyDepthbuffer( int x, int y, int width, int height );
2019-11-11 19:27:44 +00:00
2022-02-21 15:29:53 +00:00
void UploadScratch( const byte* pic, int width, int height, nvrhi::ICommandList* commandList );
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// estimates size of the GL image based on dimensions and storage type
int StorageSize() const;
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// print a one line summary of the image
void Print() const;
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// check for changed timestamp on disk and reload if necessary
2022-02-21 15:29:53 +00:00
void Reload( bool force, nvrhi::ICommandList* commandList );
2019-11-11 19:27:44 +00:00
void AddReference()
{
refCount++;
};
2019-11-11 19:27:44 +00:00
2022-02-21 15:29:53 +00:00
void MakeDefault( nvrhi::ICommandList* commandList ); // fill with a grid pattern
2019-11-11 19:27:44 +00:00
const idImageOpts& GetOpts() const
{
return opts;
}
int GetUploadWidth() const
{
return opts.width;
}
int GetUploadHeight() const
{
return opts.height;
}
2019-11-11 19:27:44 +00:00
idVec2i GetUploadResolution() const
{
return idVec2i( opts.width, opts.height );
}
void SetReferencedOutsideLevelLoad()
{
referencedOutsideLevelLoad = true;
}
void SetReferencedInsideLevelLoad()
{
levelLoadReferenced = true;
}
2022-02-21 15:29:53 +00:00
void ActuallyLoadImage( bool fromBackEnd, nvrhi::ICommandList* commandList );
2022-02-21 15:29:53 +00:00
// Adds the image to the list of images to load on the main thread to the gpu.
void DeferredLoadImage();
2019-11-11 19:27:44 +00:00
// Removes the image from the list of images to load on the main thread to the gpu.
void DeferredPurgeImage();
2012-11-26 18:58:24 +00:00
//---------------------------------------------
// Platform specific implementations
//---------------------------------------------
2019-11-11 19:27:44 +00:00
#if defined( USE_AMD_ALLOCATOR )
static void EmptyGarbage();
#endif
void AllocImage( const idImageOpts& imgOpts, textureFilter_t filter, textureRepeat_t repeat );
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// Deletes the texture object, but leaves the structure so it can be reloaded
// or resized.
void PurgeImage();
2019-11-11 19:27:44 +00:00
// z is 0 for 2D textures, 0 - 5 for cube maps, and 0 - uploadDepth for 3D textures. Only
// one plane at a time of 3D textures can be uploaded. The data is assumed to be correct for
// the format, either bytes, halfFloats, floats, or DXT compressed. The data is assumed to
// be in OpenGL RGBA format, the consoles may have to reorganize. pixelPitch is only needed
// when updating from a source subrect. Width, height, and dest* are always in pixels, so
2012-11-26 18:58:24 +00:00
// they must be a multiple of four for dxt data.
void SubImageUpload( int mipLevel, int destX, int destY, int destZ,
int width, int height, const void* data,
2022-02-21 15:29:53 +00:00
nvrhi::ICommandList* commandList,
2018-10-05 19:43:55 +00:00
int pixelPitch = 0 );
2019-11-11 19:27:44 +00:00
// some scratch images are dynamically resized based on the display window size. This
// simply purges the image and recreates it if the sizes are different, so it should not be
2012-11-26 18:58:24 +00:00
// done under any normal circumstances, and probably not at all on consoles.
void Resize( int width, int height );
2019-11-11 19:27:44 +00:00
bool IsCompressed() const
{
return ( opts.format == FMT_DXT1 || opts.format == FMT_DXT5 );
}
2019-11-11 19:27:44 +00:00
textureUsage_t GetUsage() const
{
return usage;
}
2019-11-11 19:27:44 +00:00
bool IsLoaded() const;
2019-11-11 19:27:44 +00:00
2022-02-21 15:29:53 +00:00
// Creates a sampler for this texture to use in the shader.
void CreateSampler();
// RB
bool IsDefaulted() const
{
return defaulted;
}
2017-09-03 11:56:30 +00:00
static void GetGeneratedName( idStr& _name, const textureUsage_t& _usage, const cubeFiles_t& _cube );
2019-11-11 19:27:44 +00:00
2017-09-03 11:56:30 +00:00
// used by callback functions to specify the actual data
// data goes from the bottom to the top line of the image, as OpenGL expects it
// These perform an implicit Bind() on the current texture unit
// FIXME: should we implement cinematics this way, instead of with explicit calls?
void GenerateImage( const byte* pic,
int width, int height,
textureFilter_t filter,
textureRepeat_t repeat,
textureUsage_t usage,
2022-02-21 15:29:53 +00:00
nvrhi::ICommandList* commandList,
bool isRenderTarget = false,
2022-04-12 16:15:48 +00:00
bool isUAV = false,
uint sampleCount = 1,
2022-02-21 15:29:53 +00:00
cubeFiles_t cubeFiles = CF_2D );
2019-11-11 19:27:44 +00:00
2017-09-03 11:56:30 +00:00
void GenerateCubeImage( const byte* pic[6], int size,
2022-02-21 15:29:53 +00:00
textureFilter_t filter, textureUsage_t usage, nvrhi::ICommandList* commandList );
2019-11-11 19:27:44 +00:00
2017-09-03 11:56:30 +00:00
void SetTexParameters(); // update aniso and trilinear
2019-11-11 19:27:44 +00:00
// DG: added for imgui integration (to be used with ImGui::Image() etc)
void* GetImGuiTextureID()
{
2022-02-21 18:21:16 +00:00
return nullptr;
}
// DG end
2019-11-11 19:27:44 +00:00
2022-02-21 15:29:53 +00:00
nvrhi::TextureHandle GetTextureHandle()
{
return texture;
}
void* GetTextureID()
{
return ( void* )texture.Get();
}
void* GetSampler( SamplerCache& samplerCache );
2022-02-21 15:29:53 +00:00
2022-03-22 10:16:44 +00:00
void* GetSampler( nvrhi::IDevice* device )
2022-02-21 15:29:53 +00:00
{
2022-03-22 10:16:44 +00:00
if( !sampler )
{
sampler = device->createSampler( samplerDesc );
}
return ( void* )sampler;
2022-02-21 15:29:53 +00:00
}
2022-03-22 10:16:44 +00:00
nvrhi::SamplerDesc* GetSamplerDesc()
2022-02-21 15:29:53 +00:00
{
2022-03-22 10:16:44 +00:00
return &samplerDesc;
}
void SetSampler( nvrhi::SamplerHandle _sampler )
{
sampler = _sampler;
2022-02-21 15:29:53 +00:00
}
2012-11-26 18:58:24 +00:00
private:
friend class idImageManager;
2019-11-11 19:27:44 +00:00
2022-02-21 15:29:53 +00:00
void DeriveOpts();
void AllocImage();
void SetSamplerState( textureFilter_t tf, textureRepeat_t tr );
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// parameters that define this image
idStr imgName; // game path, including extension (except for cube maps), may be an image program
cubeFiles_t cubeFiles; // If this is a cube map, and if so, what kind
int cubeMapSize;
ImageGeneratorFunction generatorFunction; // NULL for files
textureUsage_t usage; // Used to determine the type of compression to use
idImageOpts opts; // Parameters that determine the storage method
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// Sampler settings
textureFilter_t filter;
textureRepeat_t repeat;
2019-11-11 19:27:44 +00:00
2022-02-21 15:29:53 +00:00
bool isLoaded;
2012-11-26 18:58:24 +00:00
bool referencedOutsideLevelLoad;
bool levelLoadReferenced; // for determining if it needs to be purged
bool defaulted; // true if the default image was generated because a file couldn't be loaded
ID_TIME_T sourceFileTime; // the most recent of all images used in creation, for reloadImages command
ID_TIME_T binaryFileTime; // the time stamp of the binary file
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
int refCount; // overall ref count
2019-11-11 19:27:44 +00:00
static const uint32 TEXTURE_NOT_LOADED = 0xFFFFFFFF;
2019-11-11 19:27:44 +00:00
2022-02-21 15:29:53 +00:00
nvrhi::TextureHandle texture;
nvrhi::SamplerHandle sampler;
nvrhi::SamplerDesc samplerDesc;
#if defined( USE_AMD_ALLOCATOR )
VkImage image;
VmaAllocation allocation;
static int garbageIndex;
static idList< VkImage > imageGarbage[ NUM_FRAME_DATA ];
static idList< VmaAllocation > allocationGarbage[ NUM_FRAME_DATA ];
#endif
2012-11-26 18:58:24 +00:00
};
// data is RGBA
void LoadSTB_RGBA8( const char* name, byte** pic, int* width, int* height, ID_TIME_T* timestamp );
void LoadTGA( const char* name, byte** pic, int* width, int* height, ID_TIME_T* timestamp );
void R_WriteTGA( const char* filename, const byte* data, int width, int height, bool flipVertical = false, const char* basePath = "fs_savepath" );
2012-11-26 18:58:24 +00:00
// data is in top-to-bottom raster order unless flipVertical is set
// RB begin
void R_WritePNG( const char* filename, const byte* data, int bytesPerPixel, int width, int height, const char* basePath = "fs_savepath" );
void R_WriteEXR( const char* filename, const void* data, int channelsPerPixel, int width, int height, const char* basePath = "fs_savepath" );
// RB end
2012-11-26 18:58:24 +00:00
class idImageManager
{
2012-11-26 18:58:24 +00:00
public:
idImageManager()
2012-11-26 18:58:24 +00:00
{
insideLevelLoad = false;
preloadingMapImages = false;
2022-02-21 15:29:53 +00:00
commandList = nullptr;
2012-11-26 18:58:24 +00:00
}
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
void Init();
void Shutdown();
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// If the exact combination of parameters has been asked for already, an existing
// image will be returned, otherwise a new image will be created.
// Be careful not to use the same image file with different filter / repeat / etc parameters
// if possible, because it will cause a second copy to be loaded.
// If the load fails for any reason, the image will be filled in with the default
// grid pattern.
// Will automatically execute image programs if needed.
idImage* ImageFromFile( const char* name,
2022-02-21 15:29:53 +00:00
textureFilter_t filter, textureRepeat_t repeat, textureUsage_t usage, cubeFiles_t cubeMap = CF_2D, int cubeMapSize = 0 );
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// look for a loaded image, whatever the parameters
idImage* GetImage( const char* name ) const;
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// look for a loaded image, whatever the parameters
idImage* GetImageWithParameters( const char* name, textureFilter_t filter, textureRepeat_t repeat, textureUsage_t usage, cubeFiles_t cubeMap ) const;
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// The callback will be issued immediately, and later if images are reloaded or vid_restart
// The callback function should call one of the idImage::Generate* functions to fill in the data
idImage* ImageFromFunction( const char* name, ImageGeneratorFunction generatorFunction );
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// scratch images are for internal renderer use. ScratchImage names should always begin with an underscore
idImage* ScratchImage( const char* name, idImageOpts* imgOpts, textureFilter_t filter, textureRepeat_t repeat, textureUsage_t usage );
2019-11-11 19:27:44 +00:00
// These images are for internal renderer use. Names should start with "_".
idImage* ScratchImage( const char* name, const idImageOpts& opts );
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// purges all the images before a vid_restart
void PurgeAllImages();
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// reloads all apropriate images after a vid_restart
2022-02-21 15:29:53 +00:00
void ReloadImages( bool all, nvrhi::ICommandList* commandList );
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// Called only by renderSystem::BeginLevelLoad
void BeginLevelLoad();
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// Called only by renderSystem::EndLevelLoad
void EndLevelLoad();
2019-11-11 19:27:44 +00:00
void Preload( const idPreloadManifest& manifest, const bool& mapPreload );
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// Loads unloaded level images
int LoadLevelImages( bool pacifier );
2019-11-11 19:27:44 +00:00
void PrintMemInfo( MemInfo_t* mi );
2019-11-11 19:27:44 +00:00
2022-02-21 15:29:53 +00:00
void LoadDeferredImages( nvrhi::ICommandList* commandList = nullptr );
2012-11-26 18:58:24 +00:00
// built-in images
2017-09-03 11:56:30 +00:00
void CreateIntrinsicImages();
idImage* defaultImage;
idImage* flatNormalMap; // 128 128 255 in all pixels
idImage* alphaNotchImage; // 2x1 texture with just 1110 and 1111 with point sampling
idImage* whiteImage; // full of 0xff
idImage* blackImage; // full of 0x00
idImage* blackDiffuseImage; // full of 0x00
2020-04-20 18:51:31 +00:00
idImage* cyanImage; // cyan
idImage* noFalloffImage; // all 255, but zero clamped
idImage* fogImage; // increasing alpha is denser fog
idImage* fogEnterImage; // adjust fogImage alpha based on terminator plane
// RB begin
2022-03-30 09:22:58 +00:00
idImage* shadowAtlasImage; // 8192 * 8192 for clustered forward shading
idImage* shadowImage[5];
idImage* jitterImage1; // shadow jitter
idImage* jitterImage4;
idImage* jitterImage16;
2015-12-23 12:53:21 +00:00
idImage* grainImage1;
idImage* randomImage256;
idImage* blueNoiseImage256;
idImage* currentRenderHDRImage;
idImage* ldrImage; // tonemapped result which can be used for further post processing
2022-04-12 16:15:48 +00:00
idImage* taaMotionVectorsImage; // motion vectors for TAA projection
idImage* taaResolvedImage;
idImage* taaFeedback1Image;
idImage* taaFeedback2Image;
2016-01-06 21:37:16 +00:00
idImage* bloomRenderImage[2];
2022-02-21 15:29:53 +00:00
idImage* glowImage[2]; // contains any glowable surface information.
idImage* glowDepthImage[2];
idImage* accumTransparencyImage;
idImage* revealTransparencyImage;
idImage* envprobeHDRImage;
idImage* envprobeDepthImage;
idImage* heatmap5Image;
idImage* heatmap7Image;
2015-12-28 20:36:25 +00:00
idImage* smaaInputImage;
2015-12-26 14:20:19 +00:00
idImage* smaaAreaImage;
idImage* smaaSearchImage;
2015-12-26 15:11:47 +00:00
idImage* smaaEdgesImage;
idImage* smaaBlendImage;
idImage* gbufferNormalsRoughnessImage; // cheap G-Buffer replacement, holds normals and surface roughness
2016-01-06 21:37:16 +00:00
idImage* ambientOcclusionImage[2]; // contain AO and bilateral filtering keys
idImage* hierarchicalZbufferImage; // zbuffer with mip maps to accelerate screen space ray tracing
idImage* imguiFontImage;
2019-11-11 19:27:44 +00:00
2020-04-20 18:51:31 +00:00
idImage* chromeSpecImage; // only for the PBR color checker chart
idImage* plasticSpecImage; // only for the PBR color checker chart
2020-04-18 15:08:32 +00:00
idImage* brdfLutImage;
2016-07-07 01:17:33 +00:00
idImage* defaultUACIrradianceCube;
idImage* defaultUACRadianceCube;
// RB end
idImage* scratchImage;
idImage* scratchImage2;
idImage* accumImage;
2023-10-18 11:06:14 +00:00
idImage* currentRenderImage; // for 3D scene SS_POST_PROCESS shaders for effects like heatHaze, in HDR now
idImage* currentDepthImage; // for motion blur, SSAO and everything that requires depth to world pos reconstruction
idImage* originalCurrentRenderImage; // currentRenderImage before any changes for stereo rendering
idImage* loadingIconImage; // loading icon must exist always
2016-07-07 01:17:33 +00:00
idImage* hellLoadingIconImage; // loading icon must exist always
idImage* guiEdit; // SP: GUI editor image
idImage* guiEditDepthStencilImage; // SP: Gui-editor image depth-stencil
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
//--------------------------------------------------------
2019-11-11 19:27:44 +00:00
idImage* AllocImage( const char* name );
idImage* AllocStandaloneImage( const char* name );
2019-11-11 19:27:44 +00:00
bool ExcludePreloadImage( const char* name );
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
idList<idImage*, TAG_IDLIB_LIST_IMAGE> images;
2022-02-21 15:29:53 +00:00
idHashIndex imageHash;
// Transient list of images to load on the main thread to the gpu. Freed after images are loaded.
idList<idImage*, TAG_IDLIB_LIST_IMAGE> imagesToLoad;
bool insideLevelLoad; // don't actually load images now
bool preloadingMapImages; // unless this is set
2019-11-11 19:27:44 +00:00
2022-02-21 15:29:53 +00:00
nvrhi::CommandListHandle commandList;
2012-11-26 18:58:24 +00:00
};
extern idImageManager* globalImages; // pointer to global list for the rest of the system
2012-11-26 18:58:24 +00:00
/*
====================================================================
IMAGEPROCESS
FIXME: make an "imageBlock" type to hold byte*,width,height?
====================================================================
*/
byte* R_Dropsample( const byte* in, int inwidth, int inheight, int outwidth, int outheight );
byte* R_ResampleTexture( const byte* in, int inwidth, int inheight, int outwidth, int outheight );
byte* R_MipMapWithAlphaSpecularity( const byte* in, int width, int height );
byte* R_MipMapWithGamma( const byte* in, int width, int height );
byte* R_MipMap( const byte* in, int width, int height );
2012-11-26 18:58:24 +00:00
// these operate in-place on the provided pixels
void R_BlendOverTexture( byte* data, int pixelCount, const byte blend[4] );
void R_HorizontalFlip( byte* data, int width, int height );
void R_VerticalFlip( byte* data, int width, int height );
void R_VerticalFlipRGB16F( byte* data, int width, int height );
void R_RotatePic( byte* data, int width );
2014-08-23 22:10:50 +00:00
void R_ApplyCubeMapTransforms( int i, byte* data, int size );
2022-02-21 15:29:53 +00:00
// SP begin
// This method takes in a cubemap from a single image. Depending on the side (0-5),
// the image will be extracted from data and returned. The dimensions will be size x size.
byte* R_GenerateCubeMapSideFromSingleImage( byte* data, int srcWidth, int srcHeight, int size, int side );
// SP end
2012-11-26 18:58:24 +00:00
idVec4 R_CalculateMipRect( uint dimensions, uint mip );
int R_CalculateUsedAtlasPixels( int dimensions );
2012-11-26 18:58:24 +00:00
/*
====================================================================
IMAGEFILES
====================================================================
*/
// RB: added texture usage for PBR _rmao[d] HACK
void R_LoadImage( const char* name, byte** pic, int* width, int* height, ID_TIME_T* timestamp, bool makePowerOf2, textureUsage_t* usage );
2012-11-26 18:58:24 +00:00
// pic is in top to bottom raster format
2022-02-21 15:29:53 +00:00
bool R_LoadCubeImages( const char* cname, cubeFiles_t extensions, byte* pic[6], int* size, ID_TIME_T* timestamp, int cubeMapSize = 0 );
2012-11-26 18:58:24 +00:00
/*
====================================================================
IMAGEPROGRAM
====================================================================
*/
void R_LoadImageProgram( const char* name, byte** pic, int* width, int* height, ID_TIME_T* timestamp, textureUsage_t* usage = NULL );
const char* R_ParsePastImageProgram( idLexer& src );
2012-11-26 18:58:24 +00:00
#endif