public class BasicGpuResourceCache extends java.lang.Object implements GpuResourceCache
setLowWater(long)
.
When a resource is removed from the cache, and if it is a recognized OpenGL resource -- a texture, a list of vertex buffer IDs, a list of display list IDs, etc. -- and there is a current Open GL context, the appropriate glDelete function is called to de-register the resource with the GPU. If there is no current OpenGL context the resource is not deleted and will likely remain allocated on the GPU until the GL context is destroyed.
Modifier and Type | Class and Description |
---|---|
static class |
BasicGpuResourceCache.CacheEntry |
Modifier and Type | Field and Description |
---|---|
protected BasicMemoryCache |
resources |
DISPLAY_LISTS, TEXTURE, VBO_BUFFERS
Constructor and Description |
---|
BasicGpuResourceCache(long loWater,
long hiWater) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all entries from this cache.
|
protected long |
computeEntrySize(BasicGpuResourceCache.CacheEntry entry) |
protected long |
computeTextureSize(BasicGpuResourceCache.CacheEntry entry) |
boolean |
contains(java.lang.Object key)
Indicates whether a resource is in the cache.
|
protected BasicGpuResourceCache.CacheEntry |
createCacheEntry(java.lang.Object resource,
java.lang.String resourceType) |
protected BasicGpuResourceCache.CacheEntry |
createCacheEntry(java.lang.Object resource,
java.lang.String resourceType,
long size) |
java.lang.Object |
get(java.lang.Object key)
Finds and returns a resource from this cache.
|
long |
getCapacity()
Indicates this cache's capacity in bytes.
|
long |
getFreeCapacity()
Indicates this cache's memory capacity not used by its cached objects.
|
long |
getLowWater()
Returns the low water level in bytes.
|
int |
getNumObjects()
Indicates the number of resources in this cache.
|
com.jogamp.opengl.util.texture.Texture |
getTexture(java.lang.Object key)
Finds and returns a texture resource from this cache.
|
long |
getUsedCapacity()
Indicates the amount of memory used by cached objects in this cache.
|
protected void |
onEntryRemoved(java.lang.Object key,
java.lang.Object clientObject) |
void |
put(java.lang.Object key,
java.lang.Object resource,
java.lang.String resourceType,
long size)
Adds a new resource to this cache.
|
void |
put(java.lang.Object key,
com.jogamp.opengl.util.texture.Texture texture)
Add a resource to this cache.
|
void |
remove(java.lang.Object key)
Removes a resource from this cache.
|
void |
setCapacity(long newCapacity)
Sets the new capacity (in bytes) for the cache.
|
void |
setLowWater(long loWater)
Sets the new low water level in bytes, which controls how aggresively the cache discards items.
|
protected final BasicMemoryCache resources
public void clear()
GpuResourceCache
clear
in interface GpuResourceCache
protected long computeEntrySize(BasicGpuResourceCache.CacheEntry entry)
protected long computeTextureSize(BasicGpuResourceCache.CacheEntry entry)
public boolean contains(java.lang.Object key)
GpuResourceCache
contains
in interface GpuResourceCache
key
- the resource's key.protected BasicGpuResourceCache.CacheEntry createCacheEntry(java.lang.Object resource, java.lang.String resourceType)
protected BasicGpuResourceCache.CacheEntry createCacheEntry(java.lang.Object resource, java.lang.String resourceType, long size)
public java.lang.Object get(java.lang.Object key)
GpuResourceCache
get
in interface GpuResourceCache
key
- the resource's key.public long getCapacity()
GpuResourceCache
getCapacity
in interface GpuResourceCache
public long getFreeCapacity()
GpuResourceCache
getFreeCapacity
in interface GpuResourceCache
GpuResourceCache.getCapacity()
public long getLowWater()
getLowWater
in interface GpuResourceCache
GpuResourceCache.setLowWater(long)
public int getNumObjects()
GpuResourceCache
getNumObjects
in interface GpuResourceCache
public com.jogamp.opengl.util.texture.Texture getTexture(java.lang.Object key)
GpuResourceCache
getTexture
in interface GpuResourceCache
key
- the texture resource's key.public long getUsedCapacity()
GpuResourceCache
getUsedCapacity
in interface GpuResourceCache
GpuResourceCache.getCapacity()
protected void onEntryRemoved(java.lang.Object key, java.lang.Object clientObject)
public void put(java.lang.Object key, java.lang.Object resource, java.lang.String resourceType, long size)
GpuResourceCache
put
in interface GpuResourceCache
key
- the key identifying the resource.resource
- the resource cached.resourceType
- the type of resource, one of the resource-type constants described above.size
- the size of the resource, expressed as the number of bytes it requires on the GPU.GpuResourceCache.put(Object, com.jogamp.opengl.util.texture.Texture)
public void put(java.lang.Object key, com.jogamp.opengl.util.texture.Texture texture)
GpuResourceCache
put
in interface GpuResourceCache
key
- the key identifying the resource.texture
- the resource to add to this cache.public void remove(java.lang.Object key)
GpuResourceCache
remove
in interface GpuResourceCache
key
- the resource's key.public void setCapacity(long newCapacity)
setCapacity
in interface GpuResourceCache
newCapacity
- the new capacity of the cache.GpuResourceCache.setLowWater(long)
public void setLowWater(long loWater)
When the cache fills, it removes items until it reaches the low water level.
Setting a high loWater level will increase cache misses, but decrease average add time, but setting a low loWater will do the opposite.
setLowWater
in interface GpuResourceCache
loWater
- the new low water level in bytes.GpuResourceCache.setCapacity(long)
,
GpuResourceCache.remove(Object)