Package com.jme3.opencl
Class ProgramCache
java.lang.Object
com.jme3.opencl.ProgramCache
Implements a simple cache system for program objects.
The program objects are saved persistently with
The programs are identified by a unique id. The following format is recommended:
saveToCache(java.lang.String, com.jme3.opencl.Program)
.
On the next run, the stored programs can then be loaded
with loadFromCache(java.lang.String, java.lang.String)
.
The programs are identified by a unique id. The following format is recommended:
id = <full name of the class using the program>.<unique identifier within that class>
.-
Constructor Summary
ConstructorDescriptionCreates a "disabled" program cache, no caching is done.ProgramCache
(Context context) Creates a new program cache using the first device from the specified context.ProgramCache
(Context context, Device device) Creates a new program cache associated with the specified context and devices. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the cache.protected String
loadFromCache
(String id) CallsloadFromCache(java.lang.String, java.lang.String)
with the additional build arguments set to""
.loadFromCache
(String id, String buildArgs) Loads the program from the cache and builds it against the current device.void
saveToCache
(String id, Program program) Saves the specified program in the cache.
-
Constructor Details
-
ProgramCache
public ProgramCache()Creates a "disabled" program cache, no caching is done.loadFromCache(java.lang.String)
will always returnnull
andsaveToCache(java.lang.String, com.jme3.opencl.Program)
does nothing.
Use this during development if you still modify your kernel code. (Otherwise, you don't see the changes because you are still use the cached version of your program) -
ProgramCache
Creates a new program cache associated with the specified context and devices. The cached programs are built against the specified device and also only the binaries linked to that device are stored.- Parameters:
context
- the OpenCL contextdevice
- the OpenCL device
-
ProgramCache
Creates a new program cache using the first device from the specified context.- Parameters:
context
- the context- See Also:
-
-
Method Details
-
getCleanFileName
-
loadFromCache
Loads the program from the cache and builds it against the current device. You can pass additional build arguments with the parameterbuildArgs
.The cached program is identified by the specified id. This id must be unique, otherwise collisions within the cache occur. Therefore, the following naming schema is recommended:
id = <full name of the class using the program>.<unique identifier within that class>
.If the program can't be loaded, built or any other exception happened,
null
is returned.- Parameters:
id
- the unique identifier of this programbuildArgs
- additional build arguments, can benull
- Returns:
- the loaded and built program, or
null
- See Also:
-
loadFromCache
CallsloadFromCache(java.lang.String, java.lang.String)
with the additional build arguments set to""
.- Parameters:
id
- a unique identifier of the program- Returns:
- the loaded and built program or
null
if this program could not be loaded from the cache - See Also:
-
saveToCache
Saves the specified program in the cache. The parameterid
denotes the name of the program. Under this id, the program is then loaded again byloadFromCache(java.lang.String, java.lang.String)
.
The id must be unique, otherwise collisions within the cache occur. Therefore, the following naming schema is recommended:id = <full name of the class using the program>.<unique identifier within that class>
.- Parameters:
id
- the program idprogram
- the program to store in the cache
-
clearCache
public void clearCache()Clears the cache. All saved program binaries are deleted.
-