Class Image
- All Implemented Interfaces:
OpenCLObject
- Direct Known Subclasses:
LwjglImage
An image object is similar to a
Buffer
, but with a specific element
format and buffer structure.
The image is specified by the
Image.ImageDescriptor
, specifying
the type and dimensions of the image, and Image.ImageFormat
, specifying
the type of each pixel.
An image is created from scratch using
Context.createImage(com.jme3.opencl.MemoryAccess, com.jme3.opencl.Image.ImageFormat, com.jme3.opencl.Image.ImageDescriptor)
or from OpenGL by
Context.bindImage(com.jme3.texture.Image, com.jme3.texture.Texture.Type, int, com.jme3.opencl.MemoryAccess)
(and alternative versions).
Most methods take long arrays as input: long[] origin
and long[] region
.
Both are arrays of length 3.
origin defines the (x, y, z) offset in pixels in the 1D, 2D or 3D
image, the (x, y) offset and the image index in the 2D image array or the (x)
offset and the image index in the 1D image array. If image is a 2D image
object, origin[2] must be 0. If image is a 1D image or 1D image buffer
object, origin[1] and origin[2] must be 0. If image is a 1D image array
object, origin[2] must be 0. If image is a 1D image array object, origin[1]
describes the image index in the 1D image array. If image is a 2D image array
object, origin[2] describes the image index in the 2D image array.
region defines the (width, height, depth) in pixels of the 1D, 2D or
3D rectangle, the (width, height) in pixels of the 2D rectangle and the
number of images of a 2D image array or the (width) in pixels of the 1D
rectangle and the number of images of a 1D image array. If image is a 2D
image object, region[2] must be 1. If image is a 1D image or 1D image buffer
object, region[1] and region[2] must be 1. If image is a 1D image array
object, region[2] must be 1. The values in region cannot be 0.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
ImageChannelOrder
specifies the number of channels and the channel layout i.e.static enum
ImageChannelType
describes the size of the channel data type.static class
The image descriptor structure describes the type and dimensions of the image or image array.static class
Describes the image format, consisting ofImage.ImageChannelOrder
andImage.ImageChannelType
.static class
Describes a mapped region of the imagestatic enum
The possible image types / dimensions.Nested classes/interfaces inherited from interface com.jme3.opencl.OpenCLObject
OpenCLObject.ObjectReleaser
-
Field Summary
Fields inherited from class com.jme3.opencl.AbstractOpenCLObject
releaser
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract Event
Acquires this image object for using.void
Acquires this image object for using.abstract void
copyTo
(CommandQueue queue, Image dest, long[] srcOrigin, long[] destOrigin, long[] region) Performs a blocking copy operation from one image to another.abstract Event
copyToAsync
(CommandQueue queue, Image dest, long[] srcOrigin, long[] destOrigin, long[] region) Performs an async/non-blocking copy operation from one image to another.abstract Event
copyToBufferAsync
(CommandQueue queue, Buffer dest, long[] srcOrigin, long[] srcRegion, long destOffset) Copies this image into the specified buffer, no format conversion is done.abstract Event
fillAsync
(CommandQueue queue, long[] origin, long[] region, int[] color) Fills the image with the specified color given as four integer variables.abstract Event
fillAsync
(CommandQueue queue, long[] origin, long[] region, ColorRGBA color) Fills the image with the specified color.abstract long
abstract long
getDepth()
abstract int
abstract long
abstract Image.ImageFormat
abstract Image.ImageType
abstract long
abstract long
abstract long
getWidth()
abstract Image.ImageMapping
map
(CommandQueue queue, long[] origin, long[] region, MappingAccess access) Maps the image into host memory.abstract Image.ImageMapping
mapAsync
(CommandQueue queue, long[] origin, long[] region, MappingAccess access) Non-blocking version ofmap(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess)
.abstract void
readImage
(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch) Performs a blocking read of the image into the specified byte buffer.abstract Event
readImageAsync
(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch) Performs an async/non-blocking read of the image into the specified byte buffer.register()
Registers this object for automatic releasing on garbage collection.abstract Event
Releases a shared image object.void
Releases a shared image object.toString()
abstract void
unmap
(CommandQueue queue, Image.ImageMapping mapping) Unmaps the mapped memoryabstract void
writeImage
(CommandQueue queue, ByteBuffer src, long[] origin, long[] region, long rowPitch, long slicePitch) Performs a blocking write from the specified byte buffer into the image.abstract Event
writeImageAsync
(CommandQueue queue, ByteBuffer src, long[] origin, long[] region, long rowPitch, long slicePitch) Performs an async/non-blocking write from the specified byte buffer into the image.Methods inherited from class com.jme3.opencl.AbstractOpenCLObject
finalize, getReleaser, release
-
Constructor Details
-
Image
-
-
Method Details
-
register
Description copied from interface:OpenCLObject
Registers this object for automatic releasing on garbage collection. By default, OpenCLObjects are not registered in theOpenCLObjectManager
, you have to release it manually by callingOpenCLObject.release()
. Without registering or releasing, a memory leak might occur.
Returnsthis
to allow calls likeBuffer buffer = clContext.createBuffer(1024).register();
.- Specified by:
register
in interfaceOpenCLObject
- Overrides:
register
in classAbstractOpenCLObject
- Returns:
this
-
getWidth
public abstract long getWidth()- Returns:
- the width of the image
-
getHeight
public abstract long getHeight()- Returns:
- the height of the image
-
getDepth
public abstract long getDepth()- Returns:
- the depth of the image
-
getRowPitch
public abstract long getRowPitch()- Returns:
- the row pitch when the image was created from a host buffer
-
getSlicePitch
public abstract long getSlicePitch()- Returns:
- the slice pitch when the image was created from a host buffer
-
getArraySize
public abstract long getArraySize()- Returns:
- the number of elements in the image array
- See Also:
-
getImageFormat
- Returns:
- the image format
-
getImageType
- Returns:
- the image type
-
getElementSize
public abstract int getElementSize()- Returns:
- the number of bytes per pixel
-
readImage
public abstract void readImage(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch) Performs a blocking read of the image into the specified byte buffer.- Parameters:
queue
- the command queuedest
- the target byte bufferorigin
- the image origin location, see class description for the formatregion
- the copied region, see class description for the formatrowPitch
- the row pitch of the target buffer, must be set to 0 if the image is 1D. If set to 0 for 2D and 3D image, the row pitch is calculated asbytesPerElement * width
slicePitch
- the slice pitch of the target buffer, must be set to 0 for 1D and 2D images. If set to 0 for 3D images, the slice pitch is calculated asrowPitch * height
-
readImageAsync
public abstract Event readImageAsync(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch) Performs an async/non-blocking read of the image into the specified byte buffer.- Parameters:
queue
- the command queuedest
- the target byte bufferorigin
- the image origin location, see class description for the formatregion
- the copied region, see class description for the formatrowPitch
- the row pitch of the target buffer, must be set to 0 if the image is 1D. If set to 0 for 2D and 3D image, the row pitch is calculated asbytesPerElement * width
slicePitch
- the slice pitch of the target buffer, must be set to 0 for 1D and 2D images. If set to 0 for 3D images, the slice pitch is calculated asrowPitch * height
- Returns:
- the event object indicating the status of the operation
-
writeImage
public abstract void writeImage(CommandQueue queue, ByteBuffer src, long[] origin, long[] region, long rowPitch, long slicePitch) Performs a blocking write from the specified byte buffer into the image.- Parameters:
queue
- the command queuesrc
- the source bufferorigin
- the image origin location, see class description for the formatregion
- the copied region, see class description for the formatrowPitch
- the row pitch of the target buffer, must be set to 0 if the image is 1D. If set to 0 for 2D and 3D image, the row pitch is calculated asbytesPerElement * width
slicePitch
- the slice pitch of the target buffer, must be set to 0 for 1D and 2D images. If set to 0 for 3D images, the slice pitch is calculated asrowPitch * height
-
writeImageAsync
public abstract Event writeImageAsync(CommandQueue queue, ByteBuffer src, long[] origin, long[] region, long rowPitch, long slicePitch) Performs an async/non-blocking write from the specified byte buffer into the image.- Parameters:
queue
- the command queuesrc
- the source bufferorigin
- the image origin location, see class description for the formatregion
- the copied region, see class description for the formatrowPitch
- the row pitch of the target buffer, must be set to 0 if the image is 1D. If set to 0 for 2D and 3D image, the row pitch is calculated asbytesPerElement * width
slicePitch
- the slice pitch of the target buffer, must be set to 0 for 1D and 2D images. If set to 0 for 3D images, the slice pitch is calculated asrowPitch * height
- Returns:
- the event object indicating the status of the operation
-
copyTo
public abstract void copyTo(CommandQueue queue, Image dest, long[] srcOrigin, long[] destOrigin, long[] region) Performs a blocking copy operation from one image to another. Important: Both images must have the same format!- Parameters:
queue
- the command queuedest
- the target imagesrcOrigin
- the source image origin, see class description for the formatdestOrigin
- the target image origin, see class description for the formatregion
- the copied region, see class description for the format
-
copyToAsync
public abstract Event copyToAsync(CommandQueue queue, Image dest, long[] srcOrigin, long[] destOrigin, long[] region) Performs an async/non-blocking copy operation from one image to another. Important: Both images must have the same format!- Parameters:
queue
- the command queuedest
- the target imagesrcOrigin
- the source image origin, see class description for the formatdestOrigin
- the target image origin, see class description for the formatregion
- the copied region, see class description for the format- Returns:
- the event object indicating the status of the operation
-
map
public abstract Image.ImageMapping map(CommandQueue queue, long[] origin, long[] region, MappingAccess access) Maps the image into host memory. The returned structure contains the mapped byte buffer and row and slice pitch. The event object is set tonull
, it is needed for the async versionmapAsync(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess)
.- Parameters:
queue
- the command queueorigin
- the image origin, see class description for the formatregion
- the mapped region, see class description for the formataccess
- the allowed memory access to the mapped memory- Returns:
- a structure describing the mapped memory
- See Also:
-
mapAsync
public abstract Image.ImageMapping mapAsync(CommandQueue queue, long[] origin, long[] region, MappingAccess access) Non-blocking version ofmap(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess)
. The returned structure contains the mapped byte buffer and row and slice pitch. The event object is used to detect when the mapped memory is available.- Parameters:
queue
- the command queueorigin
- the image origin, see class description for the formatregion
- the mapped region, see class description for the formataccess
- the allowed memory access to the mapped memory- Returns:
- a structure describing the mapped memory
- See Also:
-
unmap
Unmaps the mapped memory- Parameters:
queue
- the command queuemapping
- the mapped memory
-
fillAsync
Fills the image with the specified color. Does only work if the image channel isImage.ImageChannelType.FLOAT
orImage.ImageChannelType.HALF_FLOAT
.- Parameters:
queue
- the command queueorigin
- the image origin, see class description for the formatregion
- the size of the region, see class description for the formatcolor
- the color to fill- Returns:
- an event object to detect for the completion
-
fillAsync
Fills the image with the specified color given as four integer variables. Does not work if the image channel isImage.ImageChannelType.FLOAT
orImage.ImageChannelType.HALF_FLOAT
.- Parameters:
queue
- the command queueorigin
- the image origin, see class description for the formatregion
- the size of the region, see class description for the formatcolor
- the color to fill, must be an array of length 4- Returns:
- an event object to detect for the completion
-
copyToBufferAsync
public abstract Event copyToBufferAsync(CommandQueue queue, Buffer dest, long[] srcOrigin, long[] srcRegion, long destOffset) Copies this image into the specified buffer, no format conversion is done. This is the dual function toBuffer.copyToImageAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image, long, long[], long[])
.- Parameters:
queue
- the command queuedest
- the target buffersrcOrigin
- the image origin, see class description for the formatsrcRegion
- the copied region, see class description for the formatdestOffset
- an offset into the target buffer- Returns:
- the event object to detect the completion of the operation
-
acquireImageForSharingAsync
Acquires this image object for using. Only call this method if this image represents a shared object from OpenGL, created with e.g.Context.bindImage(com.jme3.texture.Image, com.jme3.texture.Texture.Type, int, com.jme3.opencl.MemoryAccess)
or variations. This method must be called before the image is used. After the work is done, the image must be released by callingreleaseImageForSharingAsync(com.jme3.opencl.CommandQueue)
so that OpenGL can use the image/texture/renderbuffer again.- Parameters:
queue
- the command queue- Returns:
- the event object
-
acquireImageForSharingNoEvent
Acquires this image object for using. Only call this method if this image represents a shared object from OpenGL, created with e.g.Context.bindImage(com.jme3.texture.Image, com.jme3.texture.Texture.Type, int, com.jme3.opencl.MemoryAccess)
or variations. This method must be called before the image is used. After the work is done, the image must be released by callingreleaseImageForSharingAsync(com.jme3.opencl.CommandQueue)
so that OpenGL can use the image/texture/renderbuffer again. The generated event object is directly released. This brings a performance improvement when the resource is e.g. directly used by a kernel afterwards on the same queue (this implicitly waits for this action). If you need the event, useacquireImageForSharingAsync(com.jme3.opencl.CommandQueue)
.- Parameters:
queue
- the command queue
-
releaseImageForSharingAsync
Releases a shared image object. Call this method after the image object was acquired byacquireImageForSharingAsync(com.jme3.opencl.CommandQueue)
to hand the control back to OpenGL.- Parameters:
queue
- the command queue- Returns:
- the event object
-
releaseImageForSharingNoEvent
Releases a shared image object. Call this method after the image object was acquired byacquireImageForSharingAsync(com.jme3.opencl.CommandQueue)
to hand the control back to OpenGL. The generated event object is directly released, resulting in performance improvements.- Parameters:
queue
- the command queue
-
toString
-