public class BasicGpuResourceCache extends 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(Object key)
Indicates whether a resource is in the cache.
|
protected BasicGpuResourceCache.CacheEntry |
createCacheEntry(Object resource,
String resourceType) |
protected BasicGpuResourceCache.CacheEntry |
createCacheEntry(Object resource,
String resourceType,
long size) |
Object |
get(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.
|
Texture |
getTexture(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(Object key,
Object clientObject) |
void |
put(Object key,
Object resource,
String resourceType,
long size)
Adds a new resource to this cache.
|
void |
put(Object key,
Texture texture)
Add a resource to this cache.
|
void |
remove(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(Object key)
GpuResourceCache
contains
in interface GpuResourceCache
key
- the resource's key.protected BasicGpuResourceCache.CacheEntry createCacheEntry(Object resource, String resourceType)
protected BasicGpuResourceCache.CacheEntry createCacheEntry(Object resource, String resourceType, long size)
public Object get(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 Texture getTexture(Object key)
GpuResourceCache
getTexture
in interface GpuResourceCache
key
- the texture resource's key.public long getUsedCapacity()
GpuResourceCache
getUsedCapacity
in interface GpuResourceCache
GpuResourceCache.getCapacity()
public void put(Object key, Object resource, 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(Object key, Texture texture)
GpuResourceCache
put
in interface GpuResourceCache
key
- the key identifying the resource.texture
- the resource to add to this cache.public void remove(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)
setLowWater
in interface GpuResourceCache
loWater
- the new low water level in bytes.GpuResourceCache.setCapacity(long)
,
GpuResourceCache.remove(Object)