TINMAN 3D / REALTIME TERRAIN
Software Development Kit - User Manual

class ResourceCache in Tinman.AddOns.Rendering

A cache for graphics resource objects, with an optional maximum GPU memory limit for resource objects that implement the IMemoryConsumption interface.

sealed class ResourceCache extends Disposable
  implements IResourceCache
  IResourceConsumer

Public / Attributes

CacheMemory

The maximum amount of video memory to use for caching resource objects.

public property CacheMemory { get set }
type int32
value [>=0] The maximum video memory amount, in MB.

Remarks:

Set to 0 to disable the limit.

CacheMemoryUtilization

The memory amount of cached resource objects.

public property CacheMemoryUtilization { get }
type int32
value [>=0] The cached video memory amount, in MB.

LifecycleState

Returns the lifecycle state of this object.

public virtual property LifecycleState { get }
type LifecycleState
value The lifecycle state.
inherited Disposable.LifecycleState

Public / Constructors

ResourceCache

Creates a new instance of ResourceCache.

public constructor ResourceCache (Graphics graphics)
params graphics [not-null] The graphics object to use.

Remarks:

The initial cache size (see CacheMemory) will be 128 MB or 25% of the estimated available video memory (see AvailableVideoMemory, whichever is greater.

Public / Methods

AcquireTry

Acquires a strong reference to this disposable object.

[OwnerReturn, ThreadSafe]
public method AcquireTry ()
type IDisposable
returns this if a new strong reference has been acquired, null if this object is already being disposed.
inherited Disposable.AcquireTry

Remarks:

The object will not be actually disposed by calls to Dispose when there is at least one strong reference left. Code that calls the AcquireTry method is responsible for calling the Dispose method accordingly.

This method is not intended to be used in performance-critical code. It should only be used to high-level resource management.

Clear

Evicts all cached resource objects.

public method Clear ()
implements IResourceCache.Clear

ConsumeLoadedResource

Called by ResourceLoader to provide loaded GPU resource objects.

public method ConsumeLoadedResource (string name, IResourceHandle handle, [Owner] IResource resource, TinmanError error)
params name The resource name, as provided to Load.
  handle The resource handle, as provided to the handle parameter of Load.
  resource The GPU resource object or null if:
  error The error that has occurred while loading the resource or null on success.
implements IResourceConsumer.ConsumeLoadedResource

Dispose

Releases all resources held by this object if there are no more strong references to it, decrements the reference counter by one otherwise.

[Dispose, OwnerThis, ThreadSafe]
public method Dispose ()
inherited Disposable.Dispose

Remarks:

The Dispose method silently returns if the object has already been disposed.

Evict

Evicts a cached resource object.

public method Evict (IResourceHandle handle)
params handle The resource handle or null.
implements IResourceCache.Evict

Remarks:

After this method has been called, the next call to Get or Own will create a new resource object. The evicted resource is not necessarily disposed, because this depends on the actual disposal strategy of the implementing class.

Get

Returns a cached resource object.

public method Get (IResourceHandle handle, IResourceHandle preload = null)
type IResource
params handle The resource handle or null. If handle does not implement the IPreloadingResourceHandle interface or CanPreloadResource returns false, the preload parameter is ignored and this method behaves as if it were null.
  preload If null, the calling thread will be blocked until the handle resource has been loaded. Otherwise, the handle resource is preloaded in the background (if not null) and the cached resource object of preload is returned instead. Defaults to null.
returns The cached resource object or null if both handle and preload are null or it either one has returned a null resource object.
implements IResourceCache.Get

Remarks:

The returned resource object will be disposed automatically, usually when this IResourceCache object is disposed. However, implementing classes are free to choose other disposal strategies.

Own

Returns a cached resource object.

[OwnerReturn]
public method Own (IResourceHandle handle)
type IResource
params handle The resource handle or null.
returns The cached resource object or null if handle is null.
implements IResourceCache.Own