public abstract class Context extends AbstractOpenCLObject
JmeContext.getOpenCLContext()
.
The context is used to:
OpenCLObject.ObjectReleaser
releaser
Modifier | Constructor and Description |
---|---|
protected |
Context(OpenCLObject.ObjectReleaser releaser) |
Modifier and Type | Method and Description |
---|---|
abstract Image |
bindImage(Image image,
Texture.Type textureType,
int miplevel,
MemoryAccess access)
Creates a shared image object from a jME3-image.
|
Image |
bindImage(Texture texture,
int miplevel,
MemoryAccess access)
Creates a shared image object from a jME3 texture.
|
Image |
bindImage(Texture texture,
MemoryAccess access)
Alternative version to
bindImage(com.jme3.texture.Texture, int, com.jme3.opencl.MemoryAccess) ,
uses miplevel=0 . |
protected abstract Image |
bindPureRenderBuffer(FrameBuffer.RenderBuffer buffer,
MemoryAccess access) |
Image |
bindRenderBuffer(FrameBuffer.RenderBuffer buffer,
MemoryAccess access)
Creates a shared image object from a jME3 render buffer.
|
abstract Buffer |
bindVertexBuffer(VertexBuffer vb,
MemoryAccess access)
Creates a shared buffer from a VertexBuffer.
|
Buffer |
createBuffer(long size)
Alternative version of
createBuffer(long, com.jme3.opencl.MemoryAccess) ,
creates a buffer with read and write access. |
abstract Buffer |
createBuffer(long size,
MemoryAccess access)
Allocates a new buffer of the specific size and access type on the device.
|
Buffer |
createBufferFromHost(java.nio.ByteBuffer data)
Alternative version of
createBufferFromHost(java.nio.ByteBuffer, com.jme3.opencl.MemoryAccess) ,
creates a buffer with read and write access. |
abstract Buffer |
createBufferFromHost(java.nio.ByteBuffer data,
MemoryAccess access)
Creates a new buffer wrapping the specific host memory.
|
abstract Image |
createImage(MemoryAccess access,
Image.ImageFormat format,
Image.ImageDescriptor descr)
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. |
abstract Program |
createProgramFromBinary(java.nio.ByteBuffer binaries,
Device device)
Creates a program from the specified binaries.
|
abstract Program |
createProgramFromSourceCode(java.lang.String sourceCode)
Creates a program object from the provided source code.
|
Program |
createProgramFromSourceCodeWithDependencies(java.lang.String sourceCode,
AssetManager assetManager)
Resolves dependencies (using
#include in the source code)
and delegates the combined source code to
createProgramFromSourceCode(java.lang.String) . |
Program |
createProgramFromSourceFiles(AssetManager assetManager,
java.util.List<java.lang.String> resources)
Alternative version of
createProgramFromSourceFilesWithInclude(com.jme3.asset.AssetManager, java.lang.String, java.util.List)
with an empty include string |
Program |
createProgramFromSourceFiles(AssetManager assetManager,
java.lang.String... resources)
Alternative version of
createProgramFromSourceFilesWithInclude(com.jme3.asset.AssetManager, java.lang.String, java.lang.String...)
with an empty include string |
Program |
createProgramFromSourceFilesWithInclude(AssetManager assetManager,
java.lang.String include,
java.util.List<java.lang.String> resources)
Creates a program object from the provided source code and files.
|
Program |
createProgramFromSourceFilesWithInclude(AssetManager assetManager,
java.lang.String include,
java.lang.String... resources)
Creates a program object from the provided source code and files.
|
CommandQueue |
createQueue()
Alternative version of
createQueue(com.jme3.opencl.Device) ,
just uses the first device returned by getDevices() . |
abstract CommandQueue |
createQueue(Device device)
Creates a command queue sending commands to the specified device.
|
abstract java.util.List<? extends Device> |
getDevices()
Returns all available devices for this context.
|
abstract Image.ImageFormat[] |
querySupportedFormats(MemoryAccess access,
Image.ImageType type)
Queries all supported image formats for a specified memory access and
image type.
|
Context |
register()
Registers this object for automatic releasing on garbage collection.
|
java.lang.String |
toString() |
finalize, getReleaser, release
protected Context(OpenCLObject.ObjectReleaser releaser)
public Context register()
OpenCLObject
OpenCLObjectManager
, you have to release it manually
by calling OpenCLObject.release()
.
Without registering or releasing, a memory leak might occur.
this
to allow calls like
Buffer buffer = clContext.createBuffer(1024).register();
.register
in interface OpenCLObject
register
in class AbstractOpenCLObject
this
public abstract java.util.List<? extends Device> getDevices()
Platform
.
They are used to create a command queue sending commands to a particular
device, see 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.
PlatformChooser
.public CommandQueue createQueue()
createQueue(com.jme3.opencl.Device)
,
just uses the first device returned by getDevices()
.public abstract CommandQueue createQueue(Device device)
getDevices()
.device
- the target devicepublic abstract Buffer createBuffer(long size, MemoryAccess access)
size
- the size of the buffer in bytesaccess
- the allowed access of this buffer from kernel codepublic Buffer createBuffer(long size)
createBuffer(long, com.jme3.opencl.MemoryAccess)
,
creates a buffer with read and write access.size
- the size of the buffer in bytespublic abstract Buffer createBufferFromHost(java.nio.ByteBuffer data, MemoryAccess access)
createBuffer(long, com.jme3.opencl.MemoryAccess)
.data
- the host buffer to useaccess
- the allowed access of this buffer from kernel codepublic Buffer createBufferFromHost(java.nio.ByteBuffer data)
createBufferFromHost(java.nio.ByteBuffer, com.jme3.opencl.MemoryAccess)
,
creates a buffer with read and write access.data
- the host buffer to usepublic abstract Image createImage(MemoryAccess access, Image.ImageFormat format, Image.ImageDescriptor descr)
ImageFormat
specifies the element type and order, like RGBA of floats.ImageDescriptor
specifies the dimension of the image.access
- the allowed access of this image from kernel codeformat
- the image formatdescr
- the image descriptorpublic abstract Image.ImageFormat[] querySupportedFormats(MemoryAccess access, Image.ImageType type)
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.access
- the memory access typetype
- the image type (1D, 2D, 3D, ...)public abstract Buffer bindVertexBuffer(VertexBuffer vb, MemoryAccess access)
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.
vb
- the vertex buffer to shareaccess
- the memory access for the kernelpublic abstract Image bindImage(Image image, Texture.Type textureType, int miplevel, MemoryAccess access)
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.
image
- the jME3 image objecttextureType
- the texture type (1D, 2D, 3D), since this is not stored in the imagemiplevel
- the mipmap level that should be sharedaccess
- the allowed memory access for kernelspublic Image bindImage(Texture texture, int miplevel, MemoryAccess access)
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.
This method is equivalent to calling
bindImage(texture.getImage(), texture.getType(), miplevel, access)
.
texture
- the jME3 texturemiplevel
- the mipmap level that should be sharedaccess
- the allowed memory access for kernelspublic Image bindImage(Texture texture, MemoryAccess access)
bindImage(com.jme3.texture.Texture, int, com.jme3.opencl.MemoryAccess)
,
uses miplevel=0
.texture
- the jME3 textureaccess
- the allowed memory access for kernelspublic Image bindRenderBuffer(FrameBuffer.RenderBuffer buffer, MemoryAccess access)
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.
buffer
- the buffer to bindaccess
- the kernel access permissionsprotected abstract Image bindPureRenderBuffer(FrameBuffer.RenderBuffer buffer, MemoryAccess access)
public abstract Program createProgramFromSourceCode(java.lang.String sourceCode)
Program.build()
.sourceCode
- the source codepublic Program createProgramFromSourceCodeWithDependencies(java.lang.String sourceCode, AssetManager assetManager)
#include
in the source code)
and delegates the combined source code to
createProgramFromSourceCode(java.lang.String)
.
Important: only absolute paths are allowed.sourceCode
- the original source codeassetManager
- the asset manager to load the filesAssetNotFoundException
- if a dependency could not be loadedpublic Program createProgramFromSourceFilesWithInclude(AssetManager assetManager, java.lang.String include, java.lang.String... resources)
The typical use case is:
.clh
.cl
)createProgramFromSourceCodeWithDependencies(java.lang.String, com.jme3.asset.AssetManager)
.assetManager
- the asset manager used to load the filesinclude
- an additional include stringresources
- an array of asset paths pointing to OpenCL source filesAssetNotFoundException
- if a file could not be loadedpublic Program createProgramFromSourceFilesWithInclude(AssetManager assetManager, java.lang.String include, java.util.List<java.lang.String> resources)
The typical use case is:
.clh
.cl
)createProgramFromSourceCodeWithDependencies(java.lang.String, com.jme3.asset.AssetManager)
.assetManager
- the asset manager used to load the filesinclude
- an additional include stringresources
- an array of asset paths pointing to OpenCL source filesAssetNotFoundException
- if a file could not be loadedpublic Program createProgramFromSourceFiles(AssetManager assetManager, java.lang.String... resources)
createProgramFromSourceFilesWithInclude(com.jme3.asset.AssetManager, java.lang.String, java.lang.String...)
with an empty include stringassetManager
- for loading assetsresources
- asset paths pointing to OpenCL source filesAssetNotFoundException
- if a file could not be loadedpublic Program createProgramFromSourceFiles(AssetManager assetManager, java.util.List<java.lang.String> resources)
createProgramFromSourceFilesWithInclude(com.jme3.asset.AssetManager, java.lang.String, java.util.List)
with an empty include stringassetManager
- for loading assetsresources
- a list of asset paths pointing to OpenCL source filesAssetNotFoundException
- if a file could not be loadedpublic abstract Program createProgramFromBinary(java.nio.ByteBuffer binaries, Device device)
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.binaries
- the binariesdevice
- the device to usepublic java.lang.String toString()
toString
in class java.lang.Object