started with context creation

define_list_fix
shamanDevel 9 years ago
parent 195a5a69be
commit bb15931fa2
  1. 229
      jme3-core/src/main/java/com/jme3/opencl/CL.java
  2. 199
      jme3-core/src/main/java/com/jme3/opencl/CommandQueue.java
  3. 259
      jme3-core/src/main/java/com/jme3/opencl/Context.java
  4. 314
      jme3-core/src/main/java/com/jme3/opencl/Kernel.java
  5. 50
      jme3-core/src/main/java/com/jme3/opencl/NativeCLObject.java
  6. 16
      jme3-core/src/main/java/com/jme3/system/AppSettings.java
  7. 5
      jme3-core/src/main/java/com/jme3/system/JmeContext.java
  8. 6
      jme3-core/src/main/java/com/jme3/system/NullContext.java
  9. 6
      jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java
  10. 67
      jme3-examples/src/main/java/jme3test/gui/opencl/HelloOpenCL.java
  11. 17
      jme3-jogl/src/main/java/com/jme3/system/jogl/JoglContext.java
  12. 236
      jme3-lwjgl/src/main/java/com/jme3/opencl/lwjgl/LwjglCL.java
  13. 53
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java
  14. 4
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java
  15. 19
      jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java

@ -35,109 +35,136 @@ import java.nio.*;
/**
* Interface for OpenCL implementations
*
* @author Sebastian Weiss
*/
public interface CL {
//temp buffers for argument passing
public static class TempBuffer {
/**
* 16-Bytes (4 floats) of a byte buffer
*/
public final ByteBuffer b16;
/**
* Short-buffer view on b16
*/
public final ShortBuffer b16s;
/**
* int buffer view on b16
*/
public final IntBuffer b16i;
/**
* long buffer view on b16
*/
public final LongBuffer b16l;
/**
* float buffer view on b16
*/
public final FloatBuffer b16f;
/**
* double buffer view on b16
*/
public final DoubleBuffer b16d;
public TempBuffer(ByteBuffer b16) {
this.b16 = b16;
b16.rewind();
this.b16s = b16.asShortBuffer();
this.b16i = b16.asIntBuffer();
this.b16l = b16.asLongBuffer();
this.b16f = b16.asFloatBuffer();
this.b16d = b16.asDoubleBuffer();
}
}
/**
* Returns up to 4 temp buffer instances
* @return
*/
TempBuffer[] getTempBuffers();
//entry point
long getContext();
//OpenCL functions
long clCreateCommandQueue(long context, long device, boolean profiling);
void clReleaseCommandQueue(long queue);
long clCreateBuffer(long context, MemoryAccess access, int size, ByteBuffer hostPtr);
long clEnqueueReadBuffer(long queue, long buffer, boolean blocking, int offset, int size, ByteBuffer ptr);
long clEnqueueWriteBuffer(long queue, long buffer, boolean blocking, int offset, int size, ByteBuffer ptr);
long clEnqueueCopyBuffer(long queue, long srcBuffer, long dstBuffer, int srcOffset, int dstOffset, int size);
long clEnqueueFillBuffer(long queue, long buffer, ByteBuffer pattern, int patternSize, int offset, int size);
long clEnqueueMapBuffer(long queue, long buffer, boolean blocking, MappingAccess flags, int offset, int size);
long clCreateImage(long context, MemoryAccess access, Context.ImageFormat format, Context.ImageDescriptor desc, ByteBuffer ptr);
Context.ImageFormat[] clGetSupportedImageFormats(long context, MemoryAccess ma, Context.ImageType type);
long clEnqueueReadImage(long queue, long image, boolean blocking, ByteBuffer origin, ByteBuffer region, int rowPitch, int slicePitch, ByteBuffer ptr);
long clEnqueueWriteImage(long queue, long image, boolean blocking, ByteBuffer origin, ByteBuffer region, int inputRowPitch, int intputSlicePitch, ByteBuffer ptr);
long clEnqueueCopyImage(long queue, long srcImage, long dstImage, ByteBuffer srcOrigin, ByteBuffer dstOrigin, ByteBuffer region);
long clEnqueueFillImage(long queue, long image, ByteBuffer fillColor, ByteBuffer origin, ByteBuffer region);
long clEnqueueCopyImageToBuffer(long queue, long srcImage, long dstBuffer, ByteBuffer srcOrigin, ByteBuffer region, int dstOffset);
long clEnqueueCopyBufferToImage(long queue, long srcBuffer, long dstImage, int srcOffset, ByteBuffer dstOrigin, ByteBuffer region);
long clEnqueueMapImage(long queue, long image, boolean blocking, MappingAccess ma, ByteBuffer origin, ByteBuffer region, int rowPitch, int slicePitch);
//temp buffers for argument passing
public static class TempBuffer {
/**
* 16-Bytes (4 floats) of a byte buffer
*/
public final ByteBuffer b16;
/**
* Short-buffer view on b16
*/
public final ShortBuffer b16s;
/**
* int buffer view on b16
*/
public final IntBuffer b16i;
/**
* long buffer view on b16
*/
public final LongBuffer b16l;
/**
* float buffer view on b16
*/
public final FloatBuffer b16f;
/**
* double buffer view on b16
*/
public final DoubleBuffer b16d;
public TempBuffer(ByteBuffer b16) {
this.b16 = b16;
b16.rewind();
this.b16s = b16.asShortBuffer();
this.b16i = b16.asIntBuffer();
this.b16l = b16.asLongBuffer();
this.b16f = b16.asFloatBuffer();
this.b16d = b16.asDoubleBuffer();
}
}
/**
* Returns up to 4 temp buffer instances
*
* @return
*/
TempBuffer[] getTempBuffers();
//entry point
long getContext();
//OpenCL functions
long clCreateCommandQueue(long context, long device, boolean profiling);
void clReleaseCommandQueue(long queue);
long clCreateBuffer(long context, MemoryAccess access, int size, ByteBuffer hostPtr);
long clEnqueueReadBuffer(long queue, long buffer, boolean blocking, int offset, int size, ByteBuffer ptr);
long clEnqueueWriteBuffer(long queue, long buffer, boolean blocking, int offset, int size, ByteBuffer ptr);
long clEnqueueCopyBuffer(long queue, long srcBuffer, long dstBuffer, int srcOffset, int dstOffset, int size);
long clEnqueueFillBuffer(long queue, long buffer, ByteBuffer pattern, int patternSize, int offset, int size);
long clEnqueueMapBuffer(long queue, long buffer, boolean blocking, MappingAccess flags, int offset, int size);
long clCreateImage(long context, MemoryAccess access, Context.ImageFormat format, Context.ImageDescriptor desc, ByteBuffer ptr);
Context.ImageFormat[] clGetSupportedImageFormats(long context, MemoryAccess ma, Context.ImageType type);
long clEnqueueReadImage(long queue, long image, boolean blocking, ByteBuffer origin, ByteBuffer region, int rowPitch, int slicePitch, ByteBuffer ptr);
long clEnqueueWriteImage(long queue, long image, boolean blocking, ByteBuffer origin, ByteBuffer region, int inputRowPitch, int intputSlicePitch, ByteBuffer ptr);
long clEnqueueCopyImage(long queue, long srcImage, long dstImage, ByteBuffer srcOrigin, ByteBuffer dstOrigin, ByteBuffer region);
long clEnqueueFillImage(long queue, long image, ByteBuffer fillColor, ByteBuffer origin, ByteBuffer region);
long clEnqueueCopyImageToBuffer(long queue, long srcImage, long dstBuffer, ByteBuffer srcOrigin, ByteBuffer region, int dstOffset);
long clEnqueueCopyBufferToImage(long queue, long srcBuffer, long dstImage, int srcOffset, ByteBuffer dstOrigin, ByteBuffer region);
long clEnqueueMapImage(long queue, long image, boolean blocking, MappingAccess ma, ByteBuffer origin, ByteBuffer region, int rowPitch, int slicePitch);
//TODO: clGetImageInfo
void clReleaseMemObject(long mem);
long clEnqueueUnmapMemObject(long queue, long mem, ByteBuffer ptr);
int getMemSize(long mem); //uses clGetMemObjectInfo
long clCreateProgramWithSource(long context, CharSequence[] sources);
//TODO: create from binary
long clReleaseProgram(long program);
void clBuildProgram(long program, long[] devices, CharSequence optpions) throws KernelCompilationException;
String getKernelNames(long program); //uses clGetProgramInfo
long clCreateKernel(long program, String kernelName);
void clReleaseKernel(long kernel);
void clSetKernelArg(long kernel, int argIndex, int argSize, ByteBuffer argValue);
String getKernelName(long kernel); //uses clGetKernelInfo
int getKernelNumArgs(long kernel); //uses clGetKernelInfo
//TODO: clGetKernelWorkGroupInfo
long clEnqueueNDRangeKernel(long queue, long kernel, int workDim,
ByteBuffer globalWorkOffset, ByteBuffer globalWorkSize, ByteBuffer localWorkSize);
void clWaitForEvents(long[] events);
void clWaitForEvent(long event);
boolean isEventCompleted(long event); //uses clGetEventInfo
void clReleaseEvent(long event);
void clFlush(long queue);
void clFinish(long queue);
void clReleaseMemObject(long mem);
long clEnqueueUnmapMemObject(long queue, long mem, ByteBuffer ptr);
int getMemSize(long mem); //uses clGetMemObjectInfo
long clCreateProgramWithSource(long context, CharSequence[] sources);
//TODO: create from binary
long clReleaseProgram(long program);
void clBuildProgram(long program, long[] devices, CharSequence optpions) throws KernelCompilationException;
String getKernelNames(long program); //uses clGetProgramInfo
long clCreateKernel(long program, String kernelName);
void clReleaseKernel(long kernel);
void clSetKernelArg(long kernel, int argIndex, int argSize, ByteBuffer argValue);
String getKernelName(long kernel); //uses clGetKernelInfo
int getKernelNumArgs(long kernel); //uses clGetKernelInfo
//TODO: clGetKernelWorkGroupInfo
long clEnqueueNDRangeKernel(long queue, long kernel, int workDim,
ByteBuffer globalWorkOffset, ByteBuffer globalWorkSize, ByteBuffer localWorkSize);
void clWaitForEvents(long[] events);
void clWaitForEvent(long event);
boolean isEventCompleted(long event); //uses clGetEventInfo
void clReleaseEvent(long event);
void clFlush(long queue);
void clFinish(long queue);
}

@ -37,97 +37,116 @@ import java.nio.ByteBuffer;
*
* @author Sebastian Weiss
*/
public final class CommandQueue {
private final long queue;
public CommandQueue(long queue) {
this.queue = queue;
}
public void read(Buffer src, ByteBuffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet");
}
public void read(Buffer src, ByteBuffer dest, int size) {
read(src, dest, size, 0);
}
public void read(Buffer src, ByteBuffer dest) {
read(src, dest, src.getSize(), 0);
}
public Event readAsync(Buffer src, ByteBuffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet");
}
public Event readAsync(Buffer src, ByteBuffer dest, int size) {
return readAsync(src, dest, size, 0);
}
public Event readAsync(Buffer src, ByteBuffer dest) {
return readAsync(src, dest, src.getSize());
}
public void write(ByteBuffer src, Buffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet");
}
public void write(ByteBuffer src, Buffer dest, int size) {
write(src, dest, size, 0);
}
public void write(ByteBuffer src, Buffer dest) {
write(src, dest, dest.getSize());
}
public Event writeAsync(ByteBuffer src, Buffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet");
}
public Event writeAsync(ByteBuffer src, Buffer dest, int size) {
return writeAsync(src, dest, size, 0);
}
public Event writeAsync(ByteBuffer src, Buffer dest) {
return writeAsync(src, dest, dest.getSize());
}
public void copyTo(Buffer src, Buffer dest, int size, int srcOffset, int destOffset) {
throw new UnsupportedOperationException("not supported yet");
}
public void copyTo(Buffer src, Buffer dest, int size) {
copyTo(src, dest, size, 0, 0);
}
public void copyTo(Buffer src, Buffer dest) {
copyTo(src, dest, src.getSize());
}
public Event copyToAsync(Buffer src, Buffer dest, int size, int srcOffset, int destOffset) {
throw new UnsupportedOperationException("not supported yet");
}
public Event copyToAsync(Buffer src, Buffer dest, int size) {
return copyToAsync(src, dest, size, 0, 0);
}
public Event copyToAsync(Buffer src, Buffer dest) {
return copyToAsync(src, dest, src.getSize());
}
public ByteBuffer map(Buffer src, int size, int offset, MappingAccess access) {
throw new UnsupportedOperationException("not supported yet");
}
public ByteBuffer map(Buffer src, int size, MappingAccess access) {
return map(src, size, 0, access);
}
public ByteBuffer map(Buffer src, MappingAccess access) {
return map(src, src.getSize(), access);
}
public void unmap(Buffer src, ByteBuffer ptr) {
throw new UnsupportedOperationException("not supported yet");
}
public final class CommandQueue extends NativeCLObject {
private final long queue;
public CommandQueue(long queue) {
this.queue = queue;
}
public void read(Buffer src, ByteBuffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet");
}
public void read(Buffer src, ByteBuffer dest, int size) {
read(src, dest, size, 0);
}
public void read(Buffer src, ByteBuffer dest) {
read(src, dest, src.getSize(), 0);
}
public Event readAsync(Buffer src, ByteBuffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet");
}
public Event readAsync(Buffer src, ByteBuffer dest, int size) {
return readAsync(src, dest, size, 0);
}
public Event readAsync(Buffer src, ByteBuffer dest) {
return readAsync(src, dest, src.getSize());
}
public void write(ByteBuffer src, Buffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet");
}
public void write(ByteBuffer src, Buffer dest, int size) {
write(src, dest, size, 0);
}
public void write(ByteBuffer src, Buffer dest) {
write(src, dest, dest.getSize());
}
public Event writeAsync(ByteBuffer src, Buffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet");
}
public Event writeAsync(ByteBuffer src, Buffer dest, int size) {
return writeAsync(src, dest, size, 0);
}
public Event writeAsync(ByteBuffer src, Buffer dest) {
return writeAsync(src, dest, dest.getSize());
}
public void copyTo(Buffer src, Buffer dest, int size, int srcOffset, int destOffset) {
throw new UnsupportedOperationException("not supported yet");
}
public void copyTo(Buffer src, Buffer dest, int size) {
copyTo(src, dest, size, 0, 0);
}
public void copyTo(Buffer src, Buffer dest) {
copyTo(src, dest, src.getSize());
}
public Event copyToAsync(Buffer src, Buffer dest, int size, int srcOffset, int destOffset) {
throw new UnsupportedOperationException("not supported yet");
}
public Event copyToAsync(Buffer src, Buffer dest, int size) {
return copyToAsync(src, dest, size, 0, 0);
}
public Event copyToAsync(Buffer src, Buffer dest) {
return copyToAsync(src, dest, src.getSize());
}
public ByteBuffer map(Buffer src, int size, int offset, MappingAccess access) {
throw new UnsupportedOperationException("not supported yet");
}
public ByteBuffer map(Buffer src, int size, MappingAccess access) {
return map(src, size, 0, access);
}
public ByteBuffer map(Buffer src, MappingAccess access) {
return map(src, src.getSize(), access);
}
public void unmap(Buffer src, ByteBuffer ptr) {
throw new UnsupportedOperationException("not supported yet");
}
//TODO: async mapping
//TODO: clEnqueueFillBuffer
//TODO: image read/write
public void flush() {
throw new UnsupportedOperationException("not supported yet");
}
public void finish() {
throw new UnsupportedOperationException("not supported yet");
}
public void flush() {
throw new UnsupportedOperationException("not supported yet");
}
public void finish() {
throw new UnsupportedOperationException("not supported yet");
}
@Override
public void deleteObject() {
throw new UnsupportedOperationException("Not supported yet.");
}
}

@ -42,127 +42,150 @@ import java.util.List;
/**
* The central OpenCL context. Every actions start from here.
*
* @author Sebastian Weiss
*/
public final class Context {
private final long context;
public Context(long context) {
this.context = context;
}
public List<? extends Device> getDevices() {
throw new UnsupportedOperationException("not supported yet");
}
public CommandQueue createQueue() {
throw new UnsupportedOperationException("not supported yet");
}
public final class Context extends NativeCLObject {
private final long context;
public Context(long context) {
this.context = context;
}
public List<? extends Device> getDevices() {
throw new UnsupportedOperationException("not supported yet");
}
public CommandQueue createQueue() {
throw new UnsupportedOperationException("not supported yet");
}
//TODO: constructor with specific device and properties
public Buffer createBuffer(int size, MemoryAccess access) {
throw new UnsupportedOperationException("not supported yet");
}
public Buffer createBuffer(int size) {
return createBuffer(size, MemoryAccess.READ_WRITE);
}
public Buffer useHostBuffer(ByteBuffer data, int size, MemoryAccess access) {
throw new UnsupportedOperationException("not supported yet");
}
public Buffer useHostBuffer(ByteBuffer data, int size) {
return useHostBuffer(data, size, MemoryAccess.READ_WRITE);
}
public static enum ImageChannelOrder {
R, Rx, A,
INTENSITY,
LUMINANCE,
RG, RGx, RA,
RGB, RGBx,
RGBA,
ARGB, BGRA
}
public static enum ImageChannelType {
SNORM_INT8,
SNORM_INT16,
UNORM_INT8,
UNROM_INT16,
UNORM_SHORT_565,
UNROM_SHORT_555,
UNORM_INT_101010,
SIGNED_INT8,
SIGNED_INT16,
SIGNED_INT32,
UNSIGNED_INT8,
UNSIGNED_INT16,
UNSIGNED_INT32,
HALF_FLOAT,
FLOAT
}
public static class ImageFormat { //Struct
public ImageChannelOrder channelOrder;
public ImageChannelType channelType;
}
public static enum ImageType {
IMAGE_1D,
IMAGE_1D_BUFFER,
IMAGE_2D,
IMAGE_3D,
IMAGE_1D_ARRAY,
IMAGE_2D_ARRAY
}
public static class ImageDescriptor { //Struct
public ImageType type;
public int width;
public int height;
public int depth;
public int arraySize;
public int rowPitch;
public int slicePitch;
public int numMipLevels;
public int numSamples;
public Buffer buffer;
}
public Buffer createImage(MemoryAccess access, ImageFormat format, ImageDescriptor descr, ByteBuffer hostPtr) {
throw new UnsupportedOperationException("not supported yet");
}
public Buffer createBuffer(int size, MemoryAccess access) {
throw new UnsupportedOperationException("not supported yet");
}
public Buffer createBuffer(int size) {
return createBuffer(size, MemoryAccess.READ_WRITE);
}
public Buffer useHostBuffer(ByteBuffer data, int size, MemoryAccess access) {
throw new UnsupportedOperationException("not supported yet");
}
public Buffer useHostBuffer(ByteBuffer data, int size) {
return useHostBuffer(data, size, MemoryAccess.READ_WRITE);
}
@Override
public void deleteObject() {
throw new UnsupportedOperationException("Not supported yet.");
}
public static enum ImageChannelOrder {
R, Rx, A,
INTENSITY,
LUMINANCE,
RG, RGx, RA,
RGB, RGBx,
RGBA,
ARGB, BGRA
}
public static enum ImageChannelType {
SNORM_INT8,
SNORM_INT16,
UNORM_INT8,
UNROM_INT16,
UNORM_SHORT_565,
UNROM_SHORT_555,
UNORM_INT_101010,
SIGNED_INT8,
SIGNED_INT16,
SIGNED_INT32,
UNSIGNED_INT8,
UNSIGNED_INT16,
UNSIGNED_INT32,
HALF_FLOAT,
FLOAT
}
public static class ImageFormat { //Struct
public ImageChannelOrder channelOrder;
public ImageChannelType channelType;
}
public static enum ImageType {
IMAGE_1D,
IMAGE_1D_BUFFER,
IMAGE_2D,
IMAGE_3D,
IMAGE_1D_ARRAY,
IMAGE_2D_ARRAY
}
public static class ImageDescriptor { //Struct
public ImageType type;
public int width;
public int height;
public int depth;
public int arraySize;
public int rowPitch;
public int slicePitch;
public int numMipLevels;
public int numSamples;
public Buffer buffer;
}
public Buffer createImage(MemoryAccess access, ImageFormat format, ImageDescriptor descr, ByteBuffer hostPtr) {
throw new UnsupportedOperationException("not supported yet");
}
//TODO: add simplified methods for 1D, 2D, 3D textures
//Interop
public Buffer bindVertexBuffer(VertexBuffer vb) {
throw new UnsupportedOperationException("not supported yet");
}
public Buffer bindIndexBuffer(IndexBuffer ib) {
if (!(ib instanceof IndexByteBuffer)
&& !(ib instanceof IndexShortBuffer)
&& !(ib instanceof IndexIntBuffer)) {
throw new IllegalArgumentException("Index buffer must be an IndexByteBuffer, IndexShortBuffer or IndexIntBuffer");
}
throw new UnsupportedOperationException("not supported yet");
}
public Buffer bindImage(Image image) {
throw new UnsupportedOperationException("not supported yet");
}
public Program createProgramFromSourceCode(String sourceCode) {
throw new UnsupportedOperationException("not supported yet");
}
public Program createProgramFromSourceFilesWithInclude(
String include, String... resources) {
//TODO: load resources
throw new UnsupportedOperationException("not implemented yet");
}
public Program createProgramFormSourcesWithInclude(String include, List<String> resources) {
return createProgramFromSourceFilesWithInclude(include, resources.toArray(new String[resources.size()]));
}
public Program createProgramFromSources(String... resources) {
return createProgramFromSourceFilesWithInclude(null, resources);
}
public Program createProgramFromSources(List<String> resources) {
return createProgramFormSourcesWithInclude(null, resources);
}
public Buffer bindVertexBuffer(VertexBuffer vb) {
throw new UnsupportedOperationException("not supported yet");
}
public Buffer bindIndexBuffer(IndexBuffer ib) {
if (!(ib instanceof IndexByteBuffer)
&& !(ib instanceof IndexShortBuffer)
&& !(ib instanceof IndexIntBuffer)) {
throw new IllegalArgumentException("Index buffer must be an IndexByteBuffer, IndexShortBuffer or IndexIntBuffer");
}
throw new UnsupportedOperationException("not supported yet");
}
public Buffer bindImage(Image image) {
throw new UnsupportedOperationException("not supported yet");
}
public Program createProgramFromSourceCode(String sourceCode) {
throw new UnsupportedOperationException("not supported yet");
}
public Program createProgramFromSourceFilesWithInclude(
String include, String... resources) {
//TODO: load resources
throw new UnsupportedOperationException("not implemented yet");
}
public Program createProgramFormSourcesWithInclude(String include, List<String> resources) {
return createProgramFromSourceFilesWithInclude(include, resources.toArray(new String[resources.size()]));
}
public Program createProgramFromSources(String... resources) {
return createProgramFromSourceFilesWithInclude(null, resources);
}
public Program createProgramFromSources(List<String> resources) {
return createProgramFormSourcesWithInclude(null, resources);
}
}

@ -39,145 +39,177 @@ import com.jme3.math.Vector4f;
*
* @author Sebastian Weiss
*/
public final class Kernel {
private final WorkSize globalWorkSize;
private final WorkSize workGroupSize;
private final long kernel;
public Kernel(long kernel) {
this.kernel = kernel;
this.globalWorkSize = new WorkSize(0);
this.workGroupSize = new WorkSize(0);
}
public String getName() {
throw new UnsupportedOperationException("not supported yet");
}
public int getArgCount() {
throw new UnsupportedOperationException("not supported yet");
}
public WorkSize getGlobalWorkSize() {
return globalWorkSize;
}
public void setGlobalWorkSize(WorkSize ws) {
globalWorkSize.set(ws);
}
public void setGlobalWorkSize(int size) {
globalWorkSize.set(1, size);
}
public void setGlobalWorkSize(int width, int height) {
globalWorkSize.set(2, width, height);
}
public void setGlobalWorkSize(int width, int height, int depth) {
globalWorkSize.set(3, width, height, depth);
}
public WorkSize getWorkGroupSize() {
return workGroupSize;
}
public void setWorkGroupSize(WorkSize ws) {
workGroupSize.set(ws);
}
public void setWorkGroupSize(int size) {
workGroupSize.set(1, size);
}
public void setWorkGroupSize(int width, int height) {
workGroupSize.set(2, width, height);
}
public void setWorkGroupSize(int width, int height, int depth) {
workGroupSize.set(3, width, height, depth);
}
public void setWorkGroupSizeToNull() {
workGroupSize.set(1, 0);
}
public void setArg(int index, LocalMemPerElement t) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, LocalMem t) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, Buffer t) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, byte b) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, short s) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, int i) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, long l) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, float f) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, double d) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, Vector2f v) {
throw new UnsupportedOperationException("not supported yet");
}
//Vector3f not supported because cl_float3 is the same as a float4
public void setArg(int index, Vector4f v) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, Quaternion q) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, Object arg) {
if (arg instanceof Byte) {
setArg(index, (byte) arg);
} else if (arg instanceof Short) {
setArg(index, (short) arg);
} else if (arg instanceof Integer) {
setArg(index, (int) arg);
} else if (arg instanceof Long) {
setArg(index, (long) arg);
} else if (arg instanceof Float) {
setArg(index, (float) arg);
} else if (arg instanceof Double) {
setArg(index, (double) arg);
} else if (arg instanceof Vector2f) {
setArg(index, (Vector2f) arg);
} else if (arg instanceof Vector4f) {
setArg(index, (Vector4f) arg);
} else if (arg instanceof Quaternion) {
setArg(index, (Quaternion) arg);
} else if (arg instanceof LocalMemPerElement) {
setArg(index, (LocalMemPerElement) arg);
} else if (arg instanceof LocalMem) {
setArg(index, (LocalMem) arg);
} else if (arg instanceof Buffer) {
setArg(index, (Buffer) arg);
} else {
throw new IllegalArgumentException("unknown kernel argument type: "+arg);
}
}
private void setArgs(Object... args) {
for (int i=0; i<args.length; ++i) {
setArg(i, args[i]);
}
}
public Event Run(CommandQueue queue) {
throw new UnsupportedOperationException("not supported yet");
}
public Event Run1(CommandQueue queue, WorkSize globalWorkSize, Object... args) {
setGlobalWorkSize(globalWorkSize);
setWorkGroupSizeToNull();
setArgs(args);
return Run(queue);
}
public Event Run2(CommandQueue queue, WorkSize globalWorkSize,
WorkSize workGroupSize, Object... args) {
setGlobalWorkSize(globalWorkSize);
setWorkGroupSize(workGroupSize);
setArgs(args);
return Run(queue);
}
public final class Kernel extends NativeCLObject {
private final WorkSize globalWorkSize;
private final WorkSize workGroupSize;
private final long kernel;
public Kernel(long kernel) {
this.kernel = kernel;
this.globalWorkSize = new WorkSize(0);
this.workGroupSize = new WorkSize(0);
}
public String getName() {
throw new UnsupportedOperationException("not supported yet");
}
public int getArgCount() {
throw new UnsupportedOperationException("not supported yet");
}
public WorkSize getGlobalWorkSize() {
return globalWorkSize;
}
public void setGlobalWorkSize(WorkSize ws) {
globalWorkSize.set(ws);
}
public void setGlobalWorkSize(int size) {
globalWorkSize.set(1, size);
}
public void setGlobalWorkSize(int width, int height) {
globalWorkSize.set(2, width, height);
}
public void setGlobalWorkSize(int width, int height, int depth) {
globalWorkSize.set(3, width, height, depth);
}
public WorkSize getWorkGroupSize() {
return workGroupSize;
}
public void setWorkGroupSize(WorkSize ws) {
workGroupSize.set(ws);
}
public void setWorkGroupSize(int size) {
workGroupSize.set(1, size);
}
public void setWorkGroupSize(int width, int height) {
workGroupSize.set(2, width, height);
}
public void setWorkGroupSize(int width, int height, int depth) {
workGroupSize.set(3, width, height, depth);
}
public void setWorkGroupSizeToNull() {
workGroupSize.set(1, 0);
}
public void setArg(int index, LocalMemPerElement t) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, LocalMem t) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, Buffer t) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, byte b) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, short s) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, int i) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, long l) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, float f) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, double d) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, Vector2f v) {
throw new UnsupportedOperationException("not supported yet");
}
//Vector3f not supported because cl_float3 is the same as a float4
public void setArg(int index, Vector4f v) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, Quaternion q) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, Object arg) {
if (arg instanceof Byte) {
setArg(index, (byte) arg);
} else if (arg instanceof Short) {
setArg(index, (short) arg);
} else if (arg instanceof Integer) {
setArg(index, (int) arg);
} else if (arg instanceof Long) {
setArg(index, (long) arg);
} else if (arg instanceof Float) {
setArg(index, (float) arg);
} else if (arg instanceof Double) {
setArg(index, (double) arg);
} else if (arg instanceof Vector2f) {
setArg(index, (Vector2f) arg);
} else if (arg instanceof Vector4f) {
setArg(index, (Vector4f) arg);
} else if (arg instanceof Quaternion) {
setArg(index, (Quaternion) arg);
} else if (arg instanceof LocalMemPerElement) {
setArg(index, (LocalMemPerElement) arg);
} else if (arg instanceof LocalMem) {
setArg(index, (LocalMem) arg);
} else if (arg instanceof Buffer) {
setArg(index, (Buffer) arg);
} else {
throw new IllegalArgumentException("unknown kernel argument type: " + arg);
}
}
private void setArgs(Object... args) {
for (int i = 0; i < args.length; ++i) {
setArg(i, args[i]);
}
}
public Event Run(CommandQueue queue) {
throw new UnsupportedOperationException("not supported yet");
}
public Event Run1(CommandQueue queue, WorkSize globalWorkSize, Object... args) {
setGlobalWorkSize(globalWorkSize);
setWorkGroupSizeToNull();
setArgs(args);
return Run(queue);
}
public Event Run2(CommandQueue queue, WorkSize globalWorkSize,
WorkSize workGroupSize, Object... args) {
setGlobalWorkSize(globalWorkSize);
setWorkGroupSize(workGroupSize);
setArgs(args);
return Run(queue);
}
@Override
public void deleteObject() {
throw new UnsupportedOperationException("Not supported yet.");
}
}

@ -0,0 +1,50 @@
/*
* Copyright (c) 2009-2016 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.opencl;
/**
*
* @author Sebastian Weiss
*/
public abstract class NativeCLObject {
protected CL cl;
public CL getCl() {
return cl;
}
public void setCl(CL cl) {
this.cl = cl;
}
public abstract void deleteObject();
}

@ -160,7 +160,8 @@ public final class AppSettings extends HashMap<String, Object> {
defaults.put("GammaCorrection", false);
defaults.put("Resizable", false);
defaults.put("SwapBuffers", true);
// defaults.put("Icons", null);
defaults.put("OpenCL", false);
// defaults.put("Icons", null);
}
/**
@ -1019,4 +1020,17 @@ public final class AppSettings extends HashMap<String, Object> {
public boolean isSwapBuffers() {
return getBoolean("SwapBuffers");
}
/**
* True to enable the creation of an OpenCL context.
*
* @param support
*/
public void setOpenCLSupport(boolean support) {
putBoolean("OpenCL", support);
}
public boolean isOpenCLSupport() {
return getBoolean("OpenCL");
}
}

@ -110,6 +110,11 @@ public interface JmeContext {
*/
public Renderer getRenderer();
/**
* @return The OpenCL context if available.
*/
public com.jme3.opencl.Context getOpenCLContext();
/**
* @return Mouse input implementation. May be null if not available.
*/

@ -37,6 +37,7 @@ import com.jme3.input.MouseInput;
import com.jme3.input.TouchInput;
import com.jme3.input.dummy.DummyKeyInput;
import com.jme3.input.dummy.DummyMouseInput;
import com.jme3.opencl.Context;
import com.jme3.renderer.Renderer;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
@ -229,4 +230,9 @@ public class NullContext implements JmeContext, Runnable {
return true; // Doesn't really matter if true or false. Either way
// RenderManager won't render anything.
}
@Override
public Context getOpenCLContext() {
return null;
}
}

@ -37,6 +37,7 @@ import com.jme3.input.MouseInput;
import com.jme3.input.TouchInput;
import com.jme3.input.awt.AwtKeyInput;
import com.jme3.input.awt.AwtMouseInput;
import com.jme3.opencl.Context;
import com.jme3.renderer.Renderer;
import com.jme3.system.*;
import java.util.ArrayList;
@ -145,6 +146,11 @@ public class AwtPanelsContext implements JmeContext {
return actualContext != null && actualContext.isRenderable();
}
@Override
public Context getOpenCLContext() {
return actualContext.getOpenCLContext();
}
public AwtPanelsContext(){
}

@ -0,0 +1,67 @@
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package jme3test.gui.opencl;
import jme3test.helloworld.*;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
/** Sample 1 - how to get started with the most simple JME 3 application.
* Display a blue 3D cube and view from all sides by
* moving the mouse and pressing the WASD keys. */
public class HelloOpenCL extends SimpleApplication {
public static void main(String[] args){
HelloOpenCL app = new HelloOpenCL();
AppSettings settings = new AppSettings(true);
settings.setOpenCLSupport(true);
app.setSettings(settings);
app.start(); // start the game
}
@Override
public void simpleInitApp() {
Box b = new Box(1, 1, 1); // create cube shape
Geometry geom = new Geometry("Box", b); // create cube geometry from the shape
Material mat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material
mat.setColor("Color", ColorRGBA.Blue); // set color of material to blue
geom.setMaterial(mat); // set the cube's material
rootNode.attachChild(geom); // make the cube appear in the scene
}
}

@ -35,6 +35,7 @@ package com.jme3.system.jogl;
import com.jme3.input.JoyInput;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.opencl.Context;
import com.jme3.renderer.Renderer;
import com.jme3.renderer.RendererException;
import com.jme3.renderer.jogl.JoglGL;
@ -84,6 +85,8 @@ public abstract class JoglContext implements JmeContext {
protected MouseInput mouseInput;
protected JoyInput joyInput;
protected com.jme3.opencl.Context clContext;
@Override
public void setSystemListener(SystemListener listener){
this.listener = listener;
@ -209,6 +212,14 @@ public abstract class JoglContext implements JmeContext {
if (joyInput != null) {
joyInput.initialize();
}
if (settings.isOpenCLSupport()) {
initOpenCL();
}
}
protected void initOpenCL() {
logger.info("Initialize OpenCL with JOGL");
}
public void internalCreate() {
@ -266,4 +277,10 @@ public abstract class JoglContext implements JmeContext {
}
return samples;
}
@Override
public Context getOpenCLContext() {
return clContext;
}
}

@ -0,0 +1,236 @@
/*
* Copyright (c) 2009-2016 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.opencl.lwjgl;
import com.jme3.opencl.Context;
import com.jme3.opencl.KernelCompilationException;
import com.jme3.opencl.MappingAccess;
import com.jme3.opencl.MemoryAccess;
import java.nio.ByteBuffer;
/**
*
* @author Sebastian Weiss
*/
public class LwjglCL implements com.jme3.opencl.CL {
@Override
public TempBuffer[] getTempBuffers() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long getContext() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clCreateCommandQueue(long context, long device, boolean profiling) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clReleaseCommandQueue(long queue) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clCreateBuffer(long context, MemoryAccess access, int size, ByteBuffer hostPtr) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueReadBuffer(long queue, long buffer, boolean blocking, int offset, int size, ByteBuffer ptr) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueWriteBuffer(long queue, long buffer, boolean blocking, int offset, int size, ByteBuffer ptr) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueCopyBuffer(long queue, long srcBuffer, long dstBuffer, int srcOffset, int dstOffset, int size) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueFillBuffer(long queue, long buffer, ByteBuffer pattern, int patternSize, int offset, int size) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueMapBuffer(long queue, long buffer, boolean blocking, MappingAccess flags, int offset, int size) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clCreateImage(long context, MemoryAccess access, Context.ImageFormat format, Context.ImageDescriptor desc, ByteBuffer ptr) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Context.ImageFormat[] clGetSupportedImageFormats(long context, MemoryAccess ma, Context.ImageType type) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueReadImage(long queue, long image, boolean blocking, ByteBuffer origin, ByteBuffer region, int rowPitch, int slicePitch, ByteBuffer ptr) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueWriteImage(long queue, long image, boolean blocking, ByteBuffer origin, ByteBuffer region, int inputRowPitch, int intputSlicePitch, ByteBuffer ptr) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueCopyImage(long queue, long srcImage, long dstImage, ByteBuffer srcOrigin, ByteBuffer dstOrigin, ByteBuffer region) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueFillImage(long queue, long image, ByteBuffer fillColor, ByteBuffer origin, ByteBuffer region) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueCopyImageToBuffer(long queue, long srcImage, long dstBuffer, ByteBuffer srcOrigin, ByteBuffer region, int dstOffset) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueCopyBufferToImage(long queue, long srcBuffer, long dstImage, int srcOffset, ByteBuffer dstOrigin, ByteBuffer region) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueMapImage(long queue, long image, boolean blocking, MappingAccess ma, ByteBuffer origin, ByteBuffer region, int rowPitch, int slicePitch) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clReleaseMemObject(long mem) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueUnmapMemObject(long queue, long mem, ByteBuffer ptr) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getMemSize(long mem) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clCreateProgramWithSource(long context, CharSequence[] sources) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clReleaseProgram(long program) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clBuildProgram(long program, long[] devices, CharSequence optpions) throws KernelCompilationException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getKernelNames(long program) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clCreateKernel(long program, String kernelName) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clReleaseKernel(long kernel) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clSetKernelArg(long kernel, int argIndex, int argSize, ByteBuffer argValue) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getKernelName(long kernel) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getKernelNumArgs(long kernel) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long clEnqueueNDRangeKernel(long queue, long kernel, int workDim, ByteBuffer globalWorkOffset, ByteBuffer globalWorkSize, ByteBuffer localWorkSize) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clWaitForEvents(long[] events) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clWaitForEvent(long event) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isEventCompleted(long event) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clReleaseEvent(long event) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clFlush(long queue) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clFinish(long queue) {
throw new UnsupportedOperationException("Not supported yet.");
}
}

@ -35,6 +35,7 @@ package com.jme3.system.lwjgl;
import com.jme3.input.lwjgl.JInputJoyInput;
import com.jme3.input.lwjgl.LwjglKeyInput;
import com.jme3.input.lwjgl.LwjglMouseInput;
import com.jme3.opencl.lwjgl.LwjglCL;
import com.jme3.renderer.Renderer;
import com.jme3.renderer.RendererException;
import com.jme3.renderer.lwjgl.LwjglGL;
@ -54,12 +55,17 @@ import com.jme3.renderer.opengl.GLTimingState;
import com.jme3.renderer.opengl.GLTracer;
import com.jme3.system.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.opencl.CL;
import org.lwjgl.opencl.CL10;
import org.lwjgl.opencl.CLPlatform;
import org.lwjgl.opengl.*;
/**
@ -81,6 +87,10 @@ public abstract class LwjglContext implements JmeContext {
protected JInputJoyInput joyInput;
protected Timer timer;
protected SystemListener listener;
protected LwjglCL clImpl;
protected CLPlatform clPlatform;
protected com.jme3.opencl.Context context;
public void setSystemListener(SystemListener listener) {
this.listener = listener;
@ -245,8 +255,47 @@ public abstract class LwjglContext implements JmeContext {
if (joyInput != null) {
joyInput.initialize();
}
}
protected void initOpenCL() {
logger.info("Initialize OpenCL wiht LWJGL2");
try {
CL.create();
} catch (LWJGLException ex) {
logger.log(Level.SEVERE, "Unable to initialize OpenCL", ex);
return;
}
List<CLPlatform> platforms = CLPlatform.getPlatforms();
StringBuilder platformInfos = new StringBuilder();
platformInfos.append("Available OpenCL platforms:\n");
ArrayList<Integer> possiblePlatforms = new ArrayList<Integer>();
for (int i=0; i<platforms.size(); ++i) {
CLPlatform platform = platforms.get(i);
platformInfos.append(" * Platform ").append(i+1).append("\n");
platformInfos.append(" * Name: ").append(platform.getInfoString(CL10.CL_PLATFORM_NAME)).append("\n");
platformInfos.append(" * Vendor: ").append(platform.getInfoString(CL10.CL_PLATFORM_VENDOR)).append("\n");
platformInfos.append(" * Version: ").append(platform.getInfoString(CL10.CL_PLATFORM_VERSION)).append("\n");
platformInfos.append(" * Profile: ").append(platform.getInfoString(CL10.CL_PLATFORM_PROFILE)).append("\n");
boolean supportsInterop = platform.getInfoString(CL10.CL_PLATFORM_EXTENSIONS).contains("cl_khr_gl_sharing");
platformInfos.append(" * Supports Interop: ").append(supportsInterop).append("\n");
if (supportsInterop) {
possiblePlatforms.add(i);
}
}
logger.info(platformInfos.toString().trim());
if (possiblePlatforms.isEmpty()) {
logger.warning("No OpenCL platform with the extension 'cl_khr_gl_sharing' found!");
return;
}
int platformIndex = possiblePlatforms.get(0);
logger.info("Choose platform with index "+(platformIndex+1));
}
public void internalDestroy() {
renderer = null;
timer = null;
@ -311,4 +360,8 @@ public abstract class LwjglContext implements JmeContext {
return timer;
}
@Override
public com.jme3.opencl.Context getOpenCLContext() {
return context;
}
}

@ -149,6 +149,10 @@ public class LwjglDisplay extends LwjglAbstractDisplay {
GL11.glEnable(ARBMultisample.GL_MULTISAMPLE_ARB);
}
}
if (settings.isOpenCLSupport()) {
initOpenCL();
}
}
protected void destroyContext(){

@ -35,6 +35,7 @@ package com.jme3.system.lwjgl;
import com.jme3.input.lwjgl.GlfwJoystickInput;
import com.jme3.input.lwjgl.GlfwKeyInput;
import com.jme3.input.lwjgl.GlfwMouseInput;
import com.jme3.opencl.Context;
import com.jme3.renderer.Renderer;
import com.jme3.renderer.RendererException;
import com.jme3.renderer.lwjgl.LwjglGL;
@ -51,7 +52,9 @@ import org.lwjgl.opengl.GLCapabilities;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.lwjgl.glfw.GLFW.GLFW_TRUE;
import org.lwjgl.opengl.ARBDebugOutput;
import static org.lwjgl.opengl.GL.createCapabilities;
@ -77,6 +80,9 @@ public abstract class LwjglContext implements JmeContext {
protected GlfwJoystickInput joyInput;
protected Timer timer;
protected SystemListener listener;
protected long clPlatform;
protected Context clContext;
public void setSystemListener(SystemListener listener) {
this.listener = listener;
@ -180,6 +186,14 @@ public abstract class LwjglContext implements JmeContext {
joyInput.initialize();
}
renderable.set(true);
if (settings.isOpenCLSupport()) {
initOpenCL();
}
}
protected void initOpenCL() {
logger.info("Initialize OpenCL with LWJGL3");
}
public void internalDestroy() {
@ -250,4 +264,9 @@ public abstract class LwjglContext implements JmeContext {
return timer;
}
@Override
public Context getOpenCLContext() {
return clContext;
}
}

Loading…
Cancel
Save