Constructor
new GpuResourceCache(capacity, lowWater)
Constructs a GPU resource cache for a specified size and low-water value.
Parameters:
Name | Type | Description |
---|---|---|
capacity |
Number | The cache capacity, in bytes. |
lowWater |
Number | The number of bytes to clear the cache to when it exceeds its capacity. |
- Source:
Throws:
-
If the specified capacity is undefined, 0 or negative or the low-water value is undefined, negative or not less than the capacity.
- Type
- ArgumentError
Members
(readonly) capacity :Number
Indicates the capacity of this cache in bytes.
Type:
- Number
- Source:
(readonly) freeCapacity :Number
Indicates the number of free bytes in this cache.
Type:
- Number
- Source:
(readonly) lowWater :Number
Indicates the low-water value for this cache in bytes, the size this cache is cleared to when it
exceeds its capacity.
Type:
- Number
- Source:
(readonly) usedCapacity :Number
Indicates the number of bytes currently used by this cache.
Type:
- Number
- Source:
Methods
clear()
Removes all resources from this cache.
- Source:
containsResource(key) → {Boolean}
Indicates whether a specified resource is in this cache.
Parameters:
Name | Type | Description |
---|---|---|
key |
String | ImageSource | The key or image source of the resource to find. |
- Source:
Returns:
true If the resource is in this cache, false if the resource
is not in this cache or the specified key is null or undefined.
- Type
- Boolean
generateCacheKey() → {String}
Creates a cache key unique to this cache, typically for a resource about to be added to this cache.
- Source:
Returns:
The generated cache key.
- Type
- String
putResource(key, resource, size)
Adds a specified resource to this cache. Replaces the existing resource for the specified key if the
cache currently contains a resource for that key.
Parameters:
Name | Type | Description |
---|---|---|
key |
String | ImageSource | The key or image source of the resource to add. |
resource |
Object | The resource to add to the cache. |
size |
Number | The resource's size in bytes. Must be greater than 0. |
- Source:
Throws:
-
If either the key or resource arguments is null or undefined or if the specified size is less than 1.
- Type
- ArgumentError
removeResource(key)
Removes the specified resource from this cache. The cache is not modified if the specified key is null or
undefined or does not correspond to an entry in the cache.
Parameters:
Name | Type | Description |
---|---|---|
key |
String | ImageSource | The key or image source of the resource to remove. |
- Source:
resourceForKey(key) → {Object}
Returns the resource associated with a specified key.
Parameters:
Name | Type | Description |
---|---|---|
key |
String | ImageSource | The key or image source of the resource to find. |
- Source:
Returns:
The resource associated with the specified key, or null if the resource is not in
this cache or the specified key is null or undefined.
- Type
- Object
retrieveTexture(gl, imageSource, wrapMode) → {Texture}
Retrieves an image and adds it to this cache when it arrives. If the specified image source is a URL, a
retrieval request for the image is made and this method returns immediately with a value of null. A redraw
event is generated when the image subsequently arrives and is added to this cache. If the image source is an
ImageSource, the image is used immediately and this method returns the Texture created and
cached for the image. No redraw event is generated in this case.
Parameters:
Name | Type | Description |
---|---|---|
gl |
WebGLRenderingContext | The current WebGL context. |
imageSource |
String | ImageSource | The image source, either a ImageSource or a String giving the URL of the image. |
wrapMode |
GL.enum | Optional. Specifies the wrap mode of the texture. Defaults to gl.CLAMP_TO_EDGE |
- Source:
Returns:
The Texture created for the image if the specified image source is an
ImageSource, otherwise null.
- Type
- Texture