HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_TextureCache Class Reference

Global cache of vulkan textures sourced from files. More...

#include <RV_TextureCache.h>

+ Inheritance diagram for RV_TextureCache:

Classes

class  Image
 
class  ImageInfo
 

Public Types

enum  PlaceholderType {
  MISSING_BLACK_CLEAR, MISSING_BLACK_SOLID, MISSING_WHITE_SOLID, MISSING_RED_SOLID,
  MISSING_NORMAL_MAP, MISSING_FALLBACK, MAX_PLACEHOLDER
}
 If the texture is missing, one of these generic placeholders is used. More...
 
enum  TexturePriority {
  PRIORITY_UNUSED, PRIORITY_LOW, PRIORITY_NORMAL, PRIORITY_HIGH,
  PRIORITY_CRITICAL
}
 

Static Public Member Functions

static void init (const UT_StringHolder &device_name)
 Initialize the cache (only used by the system during startup) More...
 
static void cleanup ()
 Destroy the cache (only used by the system during exit) More...
 
static void clear ()
 Clear all images out of the cache. More...
 
static void updateTextures ()
 Mark any textures as dirty if their file source has been modified. More...
 
static exint cacheVersion ()
 The serial version of the cache. Incremented when a texture is added. More...
 
static exint cacheRefresh ()
 
static exint currentSizeBytes ()
 
static exint freeSomeMem (exint mem_in_bytes)
 
static bool bindTexture (RV_Render *r, RV_TextureRef &map, const RV_TextureParms &map_parms, const UT_StringHolder &map_name, const UT_StringHolder &relative_to_node, RV_ImageDim tex_type, RV_ShaderVariableSet *set, const UT_StringHolder &sampler_name, bool deferred_load, bool &deferred_loaded, int &op_id, TexturePriority priority=PRIORITY_NORMAL, PlaceholderType missing=MISSING_WHITE_SOLID, UT_Vector4F *fallback_color=nullptr)
 
static bool bindTextureRef (RV_Render *r, RV_TextureRef &ref, RV_ShaderVariableSet *set, const UT_StringHolder &sampler_name)
 
static bool bindPlaceholder (RV_Render *r, RV_ImageDim tex_type, RV_ShaderVariableSet *set, const UT_StringHolder &sampler_name, PlaceholderType placeholder_type, const UT_Vector4F *fallbackcolor=nullptr)
 
static bool loadTextureRef (RV_Render *r, RV_TextureRef &map, const RV_TextureParms &map_parms, const UT_StringHolder &map_name, const UT_StringHolder &relative_to_node, RV_ImageDim tex_type, bool allow_deferred_load, bool &defer_load_finished, int &op_id, TexturePriority priority=PRIORITY_NORMAL, UT_Vector3i *resolution=nullptr)
 
static bool cacheAsTexture (RV_Render *r, RV_TextureRef &map, const PXL_Raster *source_image, const RV_TextureParms &map_parms, const UT_StringHolder &map_name)
 
static bool removeCachedTexture (RV_TextureRef &map)
 Remove a cached 2D Image. More...
 
static bool cacheImage (UT_UniquePtr< RV_VKImage > image, RV_TextureRef &map, const UT_StringHolder &map_name, UT_DimRect *udim_bounds=nullptr)
 
static UT_UniquePtr< RV_VKImageuncacheImage (RV_TextureRef &map, UT_DimRect *udim_bounds=nullptr)
 
static void checkTextureDirty (RV_TextureRef &map, bool &dirty)
 
static void checkTextureHasAlpha (const RV_TextureRef &ref, bool &has_alpha)
 Check if the texture has an alpha channel. More...
 
static const char * getFileSeparator ()
 
static void setSingleTexMemLimitMB (exint mem_in_mb)
 
static exint singleTexMemLimitMB ()
 
static void setCacheSize (exint mem_in_bytes)
 
static void setReductionFactor (fpreal reduce)
 Reduce all textures in the cache by at least this amount. More...
 
static void installHDACallback (RV_TextureHDAResolverCB resolver_func)
 For resolving. More...
 
- Static Public Member Functions inherited from UT_Cache
static const UT_ValArray
< UT_Cache * > & 
utGetCacheList ()
 get the list of caches More...
 
static void setCacheAddRemoveCB (void(*callback)(void *), void *data)
 callback to be called when a cache is added or deleted. More...
 
static int64 utClearSpaceFromCaches (int64 amount)
 this method attempts to free up 'amount' bytes from all the caches. More...
 

Protected Member Functions

exint resolveTexture (RV_Render *r, const UT_StringHolder &map_name, const UT_StringHolder &relative_to_node, const RV_TextureParms &tex_parms, RV_ImageDim tex_type, bool force_update, bool deferred_load, bool &defer_loaded, int &op_id, bool &missing_texture, UT_SharedPtr< RV_TextureRef::CacheData > &ref, TexturePriority priority, UT_Vector3i *resolution)
 
RV_TextureCache::Image privGetTexture (exint id)
 
 RV_TextureCache (const UT_StringHolder &name)
 
 ~RV_TextureCache () override
 
const char * utGetCacheName () const override
 required - return the english name for this cache. More...
 
int64 utGetCurrentSize () const override
 required - return the current cache size, in bytes More...
 
int64 utReduceCacheSizeBy (int64 amount) override
 
bool utHasMaxSize () const override
 optional - override if the cache has a well defined maximum size More...
 
int64 utGetMaxSize () const override
 
void utSetMaxSize (int64) override
 

Static Protected Member Functions

static RV_TextureCache::Image getTexture (exint id)
 
static RV_VKImagegetPlaceholder (RV_Render *r, RV_ImageDim tex_type, PlaceholderType type=MISSING_WHITE_SOLID, const UT_Vector4F *fallbackcolor=nullptr)
 

Additional Inherited Members

- Public Member Functions inherited from UT_Cache
 UT_Cache ()
 
virtual ~UT_Cache ()
 
 UT_Cache (const UT_Cache &)=delete
 
UT_Cacheoperator= (const UT_Cache &)=delete
 
void utClearCache ()
 
virtual bool utIsEnabled () const
 optional - is this cache currently operational. More...
 
virtual bool utHasMinSize () const
 
virtual int64 utGetMinSize () const
 
virtual void utSetMinSize (int64)
 
virtual bool utUpdateCacheInfo ()
 

Detailed Description

Global cache of vulkan textures sourced from files.

Definition at line 42 of file RV_TextureCache.h.

Member Enumeration Documentation

If the texture is missing, one of these generic placeholders is used.

Enumerator
MISSING_BLACK_CLEAR 
MISSING_BLACK_SOLID 
MISSING_WHITE_SOLID 
MISSING_RED_SOLID 
MISSING_NORMAL_MAP 
MISSING_FALLBACK 
MAX_PLACEHOLDER 

Definition at line 66 of file RV_TextureCache.h.

Enumerator
PRIORITY_UNUSED 
PRIORITY_LOW 
PRIORITY_NORMAL 
PRIORITY_HIGH 
PRIORITY_CRITICAL 

Definition at line 78 of file RV_TextureCache.h.

Constructor & Destructor Documentation

RV_TextureCache::RV_TextureCache ( const UT_StringHolder name)
protected
RV_TextureCache::~RV_TextureCache ( )
overrideprotected

Member Function Documentation

static bool RV_TextureCache::bindPlaceholder ( RV_Render r,
RV_ImageDim  tex_type,
RV_ShaderVariableSet set,
const UT_StringHolder sampler_name,
PlaceholderType  placeholder_type,
const UT_Vector4F fallbackcolor = nullptr 
)
static

Bind a small placeholder texture (1x1) to 'sampler_name' in 'set'. The RGBA texture color is defined by the placeholder_type, or can be a custom/ color if the type is FALLBACK. The texture is 8b unorm RGBA.

static bool RV_TextureCache::bindTexture ( RV_Render r,
RV_TextureRef map,
const RV_TextureParms map_parms,
const UT_StringHolder map_name,
const UT_StringHolder relative_to_node,
RV_ImageDim  tex_type,
RV_ShaderVariableSet set,
const UT_StringHolder sampler_name,
bool  deferred_load,
bool &  deferred_loaded,
int op_id,
TexturePriority  priority = PRIORITY_NORMAL,
PlaceholderType  missing = MISSING_WHITE_SOLID,
UT_Vector4F fallback_color = nullptr 
)
static

Load the map (if needed) and bind the resulting texture to 'sampler_name' in 'set'. If it cannot be loaded, bind a placeholder texture instead. This method is equivalent to calling loadTextureRef() and then bindTextureRef() or bindPlaceholder(). If the map is a reference to a mofr with op:, op_id will contain its unique ID.

static bool RV_TextureCache::bindTextureRef ( RV_Render r,
RV_TextureRef ref,
RV_ShaderVariableSet set,
const UT_StringHolder sampler_name 
)
static

Binds an existing texture ref to the set at 'sampler_name'. It should not be a placeholder image (use bindPlaceholder instead).

static bool RV_TextureCache::cacheAsTexture ( RV_Render r,
RV_TextureRef map,
const PXL_Raster source_image,
const RV_TextureParms map_parms,
const UT_StringHolder map_name 
)
static

Cache an existing 2D Image. The name should be prefixed with exp: (explicitly cached).

static bool RV_TextureCache::cacheImage ( UT_UniquePtr< RV_VKImage image,
RV_TextureRef map,
const UT_StringHolder map_name,
UT_DimRect udim_bounds = nullptr 
)
static

Cache an existing image. The cache takes ownership (use std::move for the image). If the image is a UDIM, you can optionally pass the bounds. The map name should be prefixed with exp: (explicitly cached).

static exint RV_TextureCache::cacheRefresh ( )
static

The serial refresh count of the cache. Incremented when the user explicity updates the textures

static exint RV_TextureCache::cacheVersion ( )
static

The serial version of the cache. Incremented when a texture is added.

static void RV_TextureCache::checkTextureDirty ( RV_TextureRef map,
bool &  dirty 
)
static

Check if the texture is out of date. Flag the ref and set dirty if so. doesn't touch either if it's current.

static void RV_TextureCache::checkTextureHasAlpha ( const RV_TextureRef ref,
bool &  has_alpha 
)
static

Check if the texture has an alpha channel.

static void RV_TextureCache::cleanup ( )
static

Destroy the cache (only used by the system during exit)

static void RV_TextureCache::clear ( )
static

Clear all images out of the cache.

static exint RV_TextureCache::currentSizeBytes ( )
static
static exint RV_TextureCache::freeSomeMem ( exint  mem_in_bytes)
static
static const char* RV_TextureCache::getFileSeparator ( )
inlinestatic

For resolving a bunch of files to a 2D array, this is the separator character between the filenames.

Definition at line 173 of file RV_TextureCache.h.

static RV_VKImage* RV_TextureCache::getPlaceholder ( RV_Render r,
RV_ImageDim  tex_type,
PlaceholderType  type = MISSING_WHITE_SOLID,
const UT_Vector4F fallbackcolor = nullptr 
)
staticprotected
static RV_TextureCache::Image RV_TextureCache::getTexture ( exint  id)
staticprotected
static void RV_TextureCache::init ( const UT_StringHolder device_name)
static

Initialize the cache (only used by the system during startup)

static void RV_TextureCache::installHDACallback ( RV_TextureHDAResolverCB  resolver_func)
static

For resolving.

static bool RV_TextureCache::loadTextureRef ( RV_Render r,
RV_TextureRef map,
const RV_TextureParms map_parms,
const UT_StringHolder map_name,
const UT_StringHolder relative_to_node,
RV_ImageDim  tex_type,
bool  allow_deferred_load,
bool &  defer_load_finished,
int op_id,
TexturePriority  priority = PRIORITY_NORMAL,
UT_Vector3i resolution = nullptr 
)
static

Load the map info a texture ref without binding it to a shader. If the map could not be loaded, map.isPlaceholder() will be true. If allow_deferred_load is true, background load the texture. Keep calling this in subsequent redraws until defer_load_finished is true.

RV_TextureCache::Image RV_TextureCache::privGetTexture ( exint  id)
protected
static bool RV_TextureCache::removeCachedTexture ( RV_TextureRef map)
static

Remove a cached 2D Image.

exint RV_TextureCache::resolveTexture ( RV_Render r,
const UT_StringHolder map_name,
const UT_StringHolder relative_to_node,
const RV_TextureParms tex_parms,
RV_ImageDim  tex_type,
bool  force_update,
bool  deferred_load,
bool &  defer_loaded,
int op_id,
bool &  missing_texture,
UT_SharedPtr< RV_TextureRef::CacheData > &  ref,
TexturePriority  priority,
UT_Vector3i resolution 
)
protected
static void RV_TextureCache::setCacheSize ( exint  mem_in_bytes)
static
static void RV_TextureCache::setReductionFactor ( fpreal  reduce)
static

Reduce all textures in the cache by at least this amount.

static void RV_TextureCache::setSingleTexMemLimitMB ( exint  mem_in_mb)
static
static exint RV_TextureCache::singleTexMemLimitMB ( )
static
static UT_UniquePtr<RV_VKImage> RV_TextureCache::uncacheImage ( RV_TextureRef map,
UT_DimRect udim_bounds = nullptr 
)
static

Remove a cached image from the cache, taking ownership of it. If udim_bounds is not null, write the bounds to it.

static void RV_TextureCache::updateTextures ( )
static

Mark any textures as dirty if their file source has been modified.

const char* RV_TextureCache::utGetCacheName ( ) const
inlineoverrideprotectedvirtual

required - return the english name for this cache.

Implements UT_Cache.

Definition at line 256 of file RV_TextureCache.h.

int64 RV_TextureCache::utGetCurrentSize ( ) const
inlineoverrideprotectedvirtual

required - return the current cache size, in bytes

Implements UT_Cache.

Definition at line 258 of file RV_TextureCache.h.

int64 RV_TextureCache::utGetMaxSize ( ) const
overrideprotectedvirtual

Reimplemented from UT_Cache.

bool RV_TextureCache::utHasMaxSize ( ) const
inlineoverrideprotectedvirtual

optional - override if the cache has a well defined maximum size

Reimplemented from UT_Cache.

Definition at line 262 of file RV_TextureCache.h.

int64 RV_TextureCache::utReduceCacheSizeBy ( int64  amount)
inlineoverrideprotectedvirtual

required - free contents of the cache by amount bytes. Returns the amount of memory (in bytes) actually freed. This does not change the cache size

Implements UT_Cache.

Definition at line 260 of file RV_TextureCache.h.

void RV_TextureCache::utSetMaxSize ( int64  )
inlineoverrideprotectedvirtual

Reimplemented from UT_Cache.

Definition at line 264 of file RV_TextureCache.h.


The documentation for this class was generated from the following file: