|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
/* |
|
|
|
|
* Copyright (c) 2009-2019 jMonkeyEngine |
|
|
|
|
* Copyright (c) 2009-2020 jMonkeyEngine |
|
|
|
|
* All rights reserved. |
|
|
|
|
* |
|
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
|
@ -75,7 +75,6 @@ import java.util.Objects; |
|
|
|
|
* @author shaman |
|
|
|
|
*/ |
|
|
|
|
public abstract class Image extends AbstractOpenCLObject { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* {@code ImageChannelType} describes the size of the channel data type. |
|
|
|
|
*/ |
|
|
|
@ -99,7 +98,7 @@ public abstract class Image extends AbstractOpenCLObject { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* {@code ImageChannelOrder} specifies the number of channels and the channel layout i.e. the |
|
|
|
|
memory layout in which channels are stored in the image. |
|
|
|
|
* memory layout in which channels are stored in the image. |
|
|
|
|
*/ |
|
|
|
|
public static enum ImageChannelOrder { |
|
|
|
|
R, Rx, A, |
|
|
|
@ -157,7 +156,6 @@ memory layout in which channels are stored in the image. |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -200,6 +198,7 @@ memory layout in which channels are stored in the image. |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Used to specify an image with the provided ByteBuffer as soruce |
|
|
|
|
* |
|
|
|
|
* @param type the image type |
|
|
|
|
* @param width the width |
|
|
|
|
* @param height the height, unused for image types {@code ImageType.IMAGE_1D*} |
|
|
|
@ -219,9 +218,11 @@ memory layout in which channels are stored in the image. |
|
|
|
|
this.slicePitch = slicePitch; |
|
|
|
|
this.hostPtr = hostPtr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Specifies an image without a host buffer, a new chunk of memory |
|
|
|
|
* will be allocated. |
|
|
|
|
* |
|
|
|
|
* @param type the image type |
|
|
|
|
* @param width the width |
|
|
|
|
* @param height the height, unused for image types {@code ImageType.IMAGE_1D*} |
|
|
|
@ -243,7 +244,6 @@ memory layout in which channels are stored in the image. |
|
|
|
|
public String toString() { |
|
|
|
|
return "ImageDescriptor{" + "type=" + type + ", width=" + width + ", height=" + height + ", depth=" + depth + ", arraySize=" + arraySize + ", rowPitch=" + rowPitch + ", slicePitch=" + slicePitch + '}'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected Image(ObjectReleaser releaser) { |
|
|
|
@ -260,36 +260,44 @@ memory layout in which channels are stored in the image. |
|
|
|
|
* @return the width of the image |
|
|
|
|
*/ |
|
|
|
|
public abstract long getWidth(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return the height of the image |
|
|
|
|
*/ |
|
|
|
|
public abstract long getHeight(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return the depth of the image |
|
|
|
|
*/ |
|
|
|
|
public abstract long getDepth(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return the row pitch when the image was created from a host buffer |
|
|
|
|
*/ |
|
|
|
|
public abstract long getRowPitch(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return the slice pitch when the image was created from a host buffer |
|
|
|
|
*/ |
|
|
|
|
public abstract long getSlicePitch(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return the number of elements in the image array |
|
|
|
|
* @see ImageType#IMAGE_1D_ARRAY |
|
|
|
|
* @see ImageType#IMAGE_2D_ARRAY |
|
|
|
|
*/ |
|
|
|
|
public abstract long getArraySize(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return the image format |
|
|
|
|
*/ |
|
|
|
|
public abstract ImageFormat getImageFormat(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return the image type |
|
|
|
|
*/ |
|
|
|
|
public abstract ImageType getImageType(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return the number of bytes per pixel |
|
|
|
|
*/ |
|
|
|
@ -297,6 +305,7 @@ memory layout in which channels are stored in the image. |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Performs a blocking read of the image into the specified byte buffer. |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @param dest the target byte buffer |
|
|
|
|
* @param origin the image origin location, see class description for the format |
|
|
|
@ -307,8 +316,10 @@ memory layout in which channels are stored in the image. |
|
|
|
|
* If set to 0 for 3D images, the slice pitch is calculated as {@code rowPitch * height} |
|
|
|
|
*/ |
|
|
|
|
public abstract void readImage(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. |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @param dest the target byte buffer |
|
|
|
|
* @param origin the image origin location, see class description for the format |
|
|
|
@ -323,6 +334,7 @@ memory layout in which channels are stored in the image. |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Performs a blocking write from the specified byte buffer into the image. |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @param src the source buffer |
|
|
|
|
* @param origin the image origin location, see class description for the format |
|
|
|
@ -333,8 +345,10 @@ memory layout in which channels are stored in the image. |
|
|
|
|
* If set to 0 for 3D images, the slice pitch is calculated as {@code rowPitch * height} |
|
|
|
|
*/ |
|
|
|
|
public abstract void writeImage(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. |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @param src the source buffer |
|
|
|
|
* @param origin the image origin location, see class description for the format |
|
|
|
@ -350,6 +364,7 @@ memory layout in which channels are stored in the image. |
|
|
|
|
/** |
|
|
|
|
* Performs a blocking copy operation from one image to another. |
|
|
|
|
* <b>Important:</b> Both images must have the same format! |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @param dest the target image |
|
|
|
|
* @param srcOrigin the source image origin, see class description for the format |
|
|
|
@ -357,9 +372,11 @@ memory layout in which channels are stored in the image. |
|
|
|
|
* @param region the copied region, see class description for the format |
|
|
|
|
*/ |
|
|
|
|
public abstract void copyTo(CommandQueue queue, Image dest, long[] srcOrigin, long[] destOrigin, long[] region); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Performs an async/non-blocking copy operation from one image to another. |
|
|
|
|
* <b>Important:</b> Both images must have the same format! |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @param dest the target image |
|
|
|
|
* @param srcOrigin the source image origin, see class description for the format |
|
|
|
@ -374,6 +391,7 @@ memory layout in which channels are stored in the image. |
|
|
|
|
* The returned structure contains the mapped byte buffer and row and slice pitch. |
|
|
|
|
* The event object is set to {@code null}, it is needed for the asnyc |
|
|
|
|
* version {@link #mapAsync(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess) }. |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @param origin the image origin, see class description for the format |
|
|
|
|
* @param region the mapped region, see class description for the format |
|
|
|
@ -382,6 +400,7 @@ memory layout in which channels are stored in the image. |
|
|
|
|
* @see #unmap(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image.ImageMapping) |
|
|
|
|
*/ |
|
|
|
|
public abstract ImageMapping map(CommandQueue queue, long[] origin, long[] region, MappingAccess access); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Non-blocking version of {@link #map(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess) }. |
|
|
|
|
* The returned structure contains the mapped byte buffer and row and slice pitch. |
|
|
|
@ -394,8 +413,10 @@ memory layout in which channels are stored in the image. |
|
|
|
|
* @see #unmap(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image.ImageMapping) |
|
|
|
|
*/ |
|
|
|
|
public abstract ImageMapping mapAsync(CommandQueue queue, long[] origin, long[] region, MappingAccess access); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Unmaps the mapped memory |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @param mapping the mapped memory |
|
|
|
|
*/ |
|
|
|
@ -421,6 +442,7 @@ memory layout in which channels are stored in the image. |
|
|
|
|
public final long slicePitch; |
|
|
|
|
/** |
|
|
|
|
* The event object used to detect when the memory is available. |
|
|
|
|
* |
|
|
|
|
* @see #mapAsync(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess) |
|
|
|
|
*/ |
|
|
|
|
public final Event event; |
|
|
|
@ -431,19 +453,20 @@ memory layout in which channels are stored in the image. |
|
|
|
|
this.slicePitch = slicePitch; |
|
|
|
|
this.event = event; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public ImageMapping(ByteBuffer buffer, long rowPitch, long slicePitch) { |
|
|
|
|
this.buffer = buffer; |
|
|
|
|
this.rowPitch = rowPitch; |
|
|
|
|
this.slicePitch = slicePitch; |
|
|
|
|
this.event = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Fills the image with the specified color. |
|
|
|
|
* Does <b>only</b> work if the image channel is {@link ImageChannelType#FLOAT} |
|
|
|
|
* or {@link ImageChannelType#HALF_FLOAT}. |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @param origin the image origin, see class description for the format |
|
|
|
|
* @param region the size of the region, see class description for the format |
|
|
|
@ -455,6 +478,7 @@ memory layout in which channels are stored in the image. |
|
|
|
|
* Fills the image with the specified color given as four integer variables. |
|
|
|
|
* Does <b>not</b> work if the image channel is {@link ImageChannelType#FLOAT} |
|
|
|
|
* or {@link ImageChannelType#HALF_FLOAT}. |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @param origin the image origin, see class description for the format |
|
|
|
|
* @param region the size of the region, see class description for the format |
|
|
|
@ -467,6 +491,7 @@ memory layout in which channels are stored in the image. |
|
|
|
|
* Copies this image into the specified buffer, no format conversion is done. |
|
|
|
|
* This is the dual function to |
|
|
|
|
* {@link Buffer#copyToImageAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image, long, long[], long[]) }. |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @param dest the target buffer |
|
|
|
|
* @param srcOrigin the image origin, see class description for the format |
|
|
|
@ -485,6 +510,7 @@ memory layout in which channels are stored in the image. |
|
|
|
|
* done, the image must be released by calling |
|
|
|
|
* {@link #releaseImageForSharingAsync(com.jme3.opencl.CommandQueue) } |
|
|
|
|
* so that OpenGL can use the image/texture/renderbuffer again. |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @return the event object |
|
|
|
|
*/ |
|
|
|
@ -518,6 +544,7 @@ memory layout in which channels are stored in the image. |
|
|
|
|
* Call this method after the image object was acquired by |
|
|
|
|
* {@link #acquireImageForSharingAsync(com.jme3.opencl.CommandQueue) } |
|
|
|
|
* to hand the control back to OpenGL. |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
* @return the event object |
|
|
|
|
*/ |
|
|
|
@ -530,6 +557,7 @@ memory layout in which channels are stored in the image. |
|
|
|
|
* to hand the control back to OpenGL. |
|
|
|
|
* The generated event object is directly released, resulting in |
|
|
|
|
* performance improvements. |
|
|
|
|
* |
|
|
|
|
* @param queue the command queue |
|
|
|
|
*/ |
|
|
|
|
public void releaseImageForSharingNoEvent(CommandQueue queue) { |
|
|
|
@ -557,5 +585,4 @@ memory layout in which channels are stored in the image. |
|
|
|
|
str.append(')'); |
|
|
|
|
return str.toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|