Class LwjglContext

All Implemented Interfaces:
OpenCLObject

public class LwjglContext extends Context
  • Constructor Details

    • LwjglContext

      public LwjglContext(org.lwjgl.opencl.CLContext context, List<LwjglDevice> devices)
  • Method Details

    • getContext

      public org.lwjgl.opencl.CLContext getContext()
    • getDevices

      public List<LwjglDevice> getDevices()
      Description copied from class: Context
      Returns all available devices for this context. These devices all belong to the same Platform. They are used to create a command queue sending commands to a particular device, see Context.createQueue(com.jme3.opencl.Device). Also, device capabilities, like the supported OpenCL version, extensions, memory size and so on, are queried over the Device instances.
      The available devices were specified by a PlatformChooser.
      Specified by:
      getDevices in class Context
      Returns:
      a list of devices
    • createQueue

      public CommandQueue createQueue(Device device)
      Description copied from class: Context
      Creates a command queue sending commands to the specified device. The device must be an entry of Context.getDevices().
      Specified by:
      createQueue in class Context
      Parameters:
      device - the target device
      Returns:
      the command queue
    • createBuffer

      public Buffer createBuffer(long size, MemoryAccess access)
      Description copied from class: Context
      Allocates a new buffer of the specific size and access type on the device.
      Specified by:
      createBuffer in class Context
      Parameters:
      size - the size of the buffer in bytes
      access - the allowed access of this buffer from kernel code
      Returns:
      the new buffer
    • createBufferFromHost

      public Buffer createBufferFromHost(ByteBuffer data, MemoryAccess access)
      Description copied from class: Context
      Creates a new buffer wrapping the specific host memory. This host memory specified by a ByteBuffer can then be used directly by kernel code, although the access might be slower than with native buffers created by Context.createBuffer(long, com.jme3.opencl.MemoryAccess).
      Specified by:
      createBufferFromHost in class Context
      Parameters:
      data - the host buffer to use
      access - the allowed access of this buffer from kernel code
      Returns:
      the new buffer
    • createImage

      public Image createImage(MemoryAccess access, Image.ImageFormat format, Image.ImageDescriptor descr)
      Description copied from class: Context
      Creates a new 1D, 2D, 3D image.
      ImageFormat specifies the element type and order, like RGBA of floats.
      ImageDescriptor specifies the dimension of the image.
      Furthermore, a ByteBuffer can be specified in the ImageDescriptor together with row and slice pitches. This buffer is then used to store the image. If no ByteBuffer is specified, a new buffer is allocated (this is the normal behaviour).
      Specified by:
      createImage in class Context
      Parameters:
      access - the allowed access of this image from kernel code
      format - the image format
      descr - the image descriptor
      Returns:
      the new image object
    • querySupportedFormats

      public Image.ImageFormat[] querySupportedFormats(MemoryAccess access, Image.ImageType type)
      Description copied from class: Context
      Queries all supported image formats for a specified memory access and image type.
      Note that the returned array may contain ImageFormat objects where ImageChannelType or ImageChannelOrder are null (or both). This is the case when the device supports new formats that are not included in this wrapper yet.
      Specified by:
      querySupportedFormats in class Context
      Parameters:
      access - the memory access type
      type - the image type (1D, 2D, 3D, ...)
      Returns:
      an array of all supported image formats
    • bindVertexBuffer

      public Buffer bindVertexBuffer(VertexBuffer vb, MemoryAccess access)
      Description copied from class: Context
      Creates a shared buffer from a VertexBuffer. The returned buffer and the vertex buffer operate on the same memory, changes in one view are visible in the other view. This can be used to modify meshes directly from OpenCL (e.g. for particle systems).
      Note: The vertex buffer must already been uploaded to the GPU, i.e. it must be used at least once for drawing.

      Before the returned buffer can be used, it must be acquired explicitly by Buffer.acquireBufferForSharingAsync(com.jme3.opencl.CommandQueue) and after modifying it, released by Buffer.releaseBufferForSharingAsync(com.jme3.opencl.CommandQueue). This is needed so that OpenGL and OpenCL operations do not interfere with each other.

      Specified by:
      bindVertexBuffer in class Context
      Parameters:
      vb - the vertex buffer to share
      access - the memory access for the kernel
      Returns:
      the new buffer
    • bindImage

      public Image bindImage(Image image, Texture.Type textureType, int mipLevel, MemoryAccess access)
      Description copied from class: Context
      Creates a shared image object from a jME3-image. The returned image shares the same memory with the jME3-image, changes in one view are visible in the other view. This can be used to modify textures and images directly from OpenCL (e.g. for post-processing effects and other texture effects).
      Note: The image must already been uploaded to the GPU, i.e. it must be used at least once for drawing.

      Before the returned image can be used, it must be acquired explicitly by Image.acquireImageForSharingAsync(com.jme3.opencl.CommandQueue) and after modifying it, released by Image.releaseImageForSharingAsync(com.jme3.opencl.CommandQueue) This is needed so that OpenGL and OpenCL operations do not interfere with each other.

      Specified by:
      bindImage in class Context
      Parameters:
      image - the jME3 image object
      textureType - the texture type (1D, 2D, 3D), since this is not stored in the image
      mipLevel - the mipmap level that should be shared
      access - the allowed memory access for kernels
      Returns:
      the OpenCL image
    • bindPureRenderBuffer

      protected Image bindPureRenderBuffer(FrameBuffer.RenderBuffer buffer, MemoryAccess access)
      Specified by:
      bindPureRenderBuffer in class Context
    • createProgramFromSourceCode

      public Program createProgramFromSourceCode(String sourceCode)
      Description copied from class: Context
      Creates a program object from the provided source code. The program still needs to be compiled using Program.build().
      Specified by:
      createProgramFromSourceCode in class Context
      Parameters:
      sourceCode - the source code
      Returns:
      the program object
    • createProgramFromBinary

      public Program createProgramFromBinary(ByteBuffer binaries, Device device)
      Description copied from class: Context
      Creates a program from the specified binaries. The binaries are created by Program.getBinary(com.jme3.opencl.Device). The returned program still needs to be build using Program.build(java.lang.String, com.jme3.opencl.Device...). Important:The device passed to Program.getBinary(..), this method and Program#build(..) must be the same. The binaries are used to build a program cache across multiple launches of the application. The programs build much faster from binaries than from sources.
      Specified by:
      createProgramFromBinary in class Context
      Parameters:
      binaries - the binaries
      device - the device to use
      Returns:
      the new program