Hello,
I am using openCL to generate heightmaps and so far I was using a buffered image. With the buffered image I could only use 8-bit integer format which resulted in steps as seen here:

To get rid of these I was wondering if I could use the jmonkey class “Image” to pass an 16-bit float format image to the kernel.
Thanks for the consideration.
1 Like
Something like this?
[java]
ByteBuffer data = BufferUtils.createByteBuffer(
(int) ((int)Math.ceil(Image.Format.RGBA16F.getBitsPerPixel() / 8 ) * height * width));
Image image = new Image();
image.setHeight(height);
image.setWidth(width);
image.setFormat(Image.Format.RGBA16F);
image.setData(data);
ImageRaster raster = ImageRaster.create(image);
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
raster.setPixel(x, y, colorData[x + (y * width)]);
}
}
[/java]
1 Like
The ImageRaster class will allow you to “paint” onto a jME3 image in the same way that you can paint onto a BufferedImage. The painting is done via 32-bit float colors and then converted to whichever format you specify for the image.
1 Like
Right, but until now I have just been doing this:
[java]
DataBufferInt intBuffer = (DataBufferInt)inout.getRaster().getDataBuffer();
int data[] = intBuffer.getData();
[/java]
and then using data as input and output for my openCL program. The thing I wanted to know was if I could do the same with a jmonkey image.
Something along the lines of this should work:
[java]
FloatBuffer fb = image.getData().get(0).asFloatBuffer();
float[] Data = new float[fb.remaining()];
fb.get(Data);
[/java]
1 Like
<cite>@romobomo said:</cite>
Something along the lines of this should work:
[java]
FloatBuffer fb = image.getData().get(0).asFloatBuffer();
float[] Data = new float[fb.remaining()];
fb.get(Data);
[/java]
Oh yea that seems to work. Now after the array is filled from the kernel how could I update the data for the image? When using a buffered image filling the array causes the pixels to be automatically changed in the image…