Class ProgramCache

java.lang.Object
com.jme3.opencl.ProgramCache

public class ProgramCache extends Object
Implements a simple cache system for program objects. The program objects are saved persistently with 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 Details

    • ProgramCache

      public ProgramCache()
      Creates a "disabled" program cache, no caching is done. loadFromCache(java.lang.String) will always return null and saveToCache(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

      public ProgramCache(Context context, Device device)
      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 context
      device - the OpenCL device
    • ProgramCache

      public ProgramCache(Context context)
      Creates a new program cache using the first device from the specified context.
      Parameters:
      context - the context
      See Also:
  • Method Details

    • getCleanFileName

      protected String getCleanFileName(String id)
    • loadFromCache

      public Program loadFromCache(String id, String buildArgs)
      Loads the program from the cache and builds it against the current device. You can pass additional build arguments with the parameter buildArgs.

      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 program
      buildArgs - additional build arguments, can be null
      Returns:
      the loaded and built program, or null
      See Also:
    • loadFromCache

      public Program loadFromCache(String id)
      Calls loadFromCache(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

      public void saveToCache(String id, Program program)
      Saves the specified program in the cache. The parameter id denotes the name of the program. Under this id, the program is then loaded again by loadFromCache(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 id
      program - the program to store in the cache
    • clearCache

      public void clearCache()
      Clears the cache. All saved program binaries are deleted.