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 * Interface for OpenCL implementations
*
* @author Sebastian Weiss * @author Sebastian Weiss
*/ */
public interface CL { public interface CL {
//temp buffers for argument passing //temp buffers for argument passing
public static class TempBuffer { public static class TempBuffer {
/**
* 16-Bytes (4 floats) of a byte buffer /**
*/ * 16-Bytes (4 floats) of a byte buffer
public final ByteBuffer b16; */
/** public final ByteBuffer b16;
* Short-buffer view on b16 /**
*/ * Short-buffer view on b16
public final ShortBuffer b16s; */
/** public final ShortBuffer b16s;
* int buffer view on b16 /**
*/ * int buffer view on b16
public final IntBuffer b16i; */
/** public final IntBuffer b16i;
* long buffer view on b16 /**
*/ * long buffer view on b16
public final LongBuffer b16l; */
/** public final LongBuffer b16l;
* float buffer view on b16 /**
*/ * float buffer view on b16
public final FloatBuffer b16f; */
/** public final FloatBuffer b16f;
* double buffer view on b16 /**
*/ * double buffer view on b16
public final DoubleBuffer b16d; */
public final DoubleBuffer b16d;
public TempBuffer(ByteBuffer b16) {
this.b16 = b16; public TempBuffer(ByteBuffer b16) {
b16.rewind(); this.b16 = b16;
this.b16s = b16.asShortBuffer(); b16.rewind();
this.b16i = b16.asIntBuffer(); this.b16s = b16.asShortBuffer();
this.b16l = b16.asLongBuffer(); this.b16i = b16.asIntBuffer();
this.b16f = b16.asFloatBuffer(); this.b16l = b16.asLongBuffer();
this.b16d = b16.asDoubleBuffer(); this.b16f = b16.asFloatBuffer();
} this.b16d = b16.asDoubleBuffer();
} }
/** }
* Returns up to 4 temp buffer instances
* @return /**
*/ * Returns up to 4 temp buffer instances
TempBuffer[] getTempBuffers(); *
* @return
//entry point */
long getContext(); TempBuffer[] getTempBuffers();
//OpenCL functions //entry point
long clCreateCommandQueue(long context, long device, boolean profiling); long getContext();
void clReleaseCommandQueue(long queue);
//OpenCL functions
long clCreateBuffer(long context, MemoryAccess access, int size, ByteBuffer hostPtr); long clCreateCommandQueue(long context, long device, boolean profiling);
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); void clReleaseCommandQueue(long queue);
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 clCreateBuffer(long context, MemoryAccess access, int size, ByteBuffer hostPtr);
long clEnqueueMapBuffer(long queue, long buffer, boolean blocking, MappingAccess flags, int offset, int size);
long clEnqueueReadBuffer(long queue, long buffer, boolean blocking, int offset, int size, ByteBuffer ptr);
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 clEnqueueWriteBuffer(long queue, long buffer, boolean blocking, int offset, int size, ByteBuffer ptr);
long clEnqueueReadImage(long queue, long image, boolean blocking, ByteBuffer origin, ByteBuffer region, int rowPitch, int slicePitch, ByteBuffer ptr); long clEnqueueCopyBuffer(long queue, long srcBuffer, long dstBuffer, int srcOffset, int dstOffset, int size);
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 clEnqueueFillBuffer(long queue, long buffer, ByteBuffer pattern, int patternSize, int offset, int size);
long clEnqueueFillImage(long queue, long image, ByteBuffer fillColor, ByteBuffer origin, ByteBuffer region);
long clEnqueueMapBuffer(long queue, long buffer, boolean blocking, MappingAccess flags, int offset, int size);
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 clCreateImage(long context, MemoryAccess access, Context.ImageFormat format, Context.ImageDescriptor desc, ByteBuffer ptr);
long clEnqueueMapImage(long queue, long image, boolean blocking, MappingAccess ma, ByteBuffer origin, ByteBuffer region, int rowPitch, int slicePitch); 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 //TODO: clGetImageInfo
void clReleaseMemObject(long mem); void clReleaseMemObject(long mem);
long clEnqueueUnmapMemObject(long queue, long mem, ByteBuffer ptr);
int getMemSize(long mem); //uses clGetMemObjectInfo long clEnqueueUnmapMemObject(long queue, long mem, ByteBuffer ptr);
long clCreateProgramWithSource(long context, CharSequence[] sources); int getMemSize(long mem); //uses clGetMemObjectInfo
//TODO: create from binary
long clReleaseProgram(long program); long clCreateProgramWithSource(long context, CharSequence[] sources);
void clBuildProgram(long program, long[] devices, CharSequence optpions) throws KernelCompilationException; //TODO: create from binary
String getKernelNames(long program); //uses clGetProgramInfo
long clReleaseProgram(long program);
long clCreateKernel(long program, String kernelName);
void clReleaseKernel(long kernel); void clBuildProgram(long program, long[] devices, CharSequence optpions) throws KernelCompilationException;
void clSetKernelArg(long kernel, int argIndex, int argSize, ByteBuffer argValue);
String getKernelName(long kernel); //uses clGetKernelInfo String getKernelNames(long program); //uses clGetProgramInfo
int getKernelNumArgs(long kernel); //uses clGetKernelInfo
//TODO: clGetKernelWorkGroupInfo long clCreateKernel(long program, String kernelName);
long clEnqueueNDRangeKernel(long queue, long kernel, int workDim, void clReleaseKernel(long kernel);
ByteBuffer globalWorkOffset, ByteBuffer globalWorkSize, ByteBuffer localWorkSize);
void clSetKernelArg(long kernel, int argIndex, int argSize, ByteBuffer argValue);
void clWaitForEvents(long[] events);
void clWaitForEvent(long event); String getKernelName(long kernel); //uses clGetKernelInfo
boolean isEventCompleted(long event); //uses clGetEventInfo
void clReleaseEvent(long event); int getKernelNumArgs(long kernel); //uses clGetKernelInfo
//TODO: clGetKernelWorkGroupInfo
void clFlush(long queue);
void clFinish(long queue); 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 * @author Sebastian Weiss
*/ */
public final class CommandQueue { public final class CommandQueue extends NativeCLObject {
private final long queue;
private final long queue;
public CommandQueue(long queue) {
this.queue = 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, 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, int size) {
public void read(Buffer src, ByteBuffer dest) { read(src, dest, size, 0);
read(src, dest, src.getSize(), 0); }
}
public void read(Buffer src, ByteBuffer dest) {
public Event readAsync(Buffer src, ByteBuffer dest, int size, int offset) { read(src, dest, src.getSize(), 0);
throw new UnsupportedOperationException("not supported yet"); }
}
public Event readAsync(Buffer src, ByteBuffer dest, int size) { public Event readAsync(Buffer src, ByteBuffer dest, int size, int offset) {
return readAsync(src, dest, size, 0); throw new UnsupportedOperationException("not supported yet");
} }
public Event readAsync(Buffer src, ByteBuffer dest) {
return readAsync(src, dest, src.getSize()); public Event readAsync(Buffer src, ByteBuffer dest, int size) {
} return readAsync(src, dest, size, 0);
}
public void write(ByteBuffer src, Buffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet"); public Event readAsync(Buffer src, ByteBuffer dest) {
} return readAsync(src, dest, src.getSize());
public void write(ByteBuffer src, Buffer dest, int size) { }
write(src, dest, size, 0);
} public void write(ByteBuffer src, Buffer dest, int size, int offset) {
public void write(ByteBuffer src, Buffer dest) { throw new UnsupportedOperationException("not supported yet");
write(src, dest, dest.getSize()); }
}
public void write(ByteBuffer src, Buffer dest, int size) {
public Event writeAsync(ByteBuffer src, Buffer dest, int size, int offset) { write(src, dest, size, 0);
throw new UnsupportedOperationException("not supported yet"); }
}
public Event writeAsync(ByteBuffer src, Buffer dest, int size) { public void write(ByteBuffer src, Buffer dest) {
return writeAsync(src, dest, size, 0); write(src, dest, dest.getSize());
} }
public Event writeAsync(ByteBuffer src, Buffer dest) {
return writeAsync(src, dest, dest.getSize()); public Event writeAsync(ByteBuffer src, Buffer dest, int size, int offset) {
} throw new UnsupportedOperationException("not supported yet");
}
public void copyTo(Buffer src, Buffer dest, int size, int srcOffset, int destOffset) {
throw new UnsupportedOperationException("not supported yet"); public Event writeAsync(ByteBuffer src, Buffer dest, int size) {
} return writeAsync(src, dest, size, 0);
public void copyTo(Buffer src, Buffer dest, int size) { }
copyTo(src, dest, size, 0, 0);
} public Event writeAsync(ByteBuffer src, Buffer dest) {
public void copyTo(Buffer src, Buffer dest) { return writeAsync(src, dest, dest.getSize());
copyTo(src, dest, src.getSize()); }
}
public void copyTo(Buffer src, Buffer dest, int size, int srcOffset, int destOffset) {
public Event copyToAsync(Buffer src, Buffer dest, int size, int srcOffset, int destOffset) { throw new UnsupportedOperationException("not supported yet");
throw new UnsupportedOperationException("not supported yet"); }
}
public Event copyToAsync(Buffer src, Buffer dest, int size) { public void copyTo(Buffer src, Buffer dest, int size) {
return copyToAsync(src, dest, size, 0, 0); copyTo(src, dest, size, 0, 0);
} }
public Event copyToAsync(Buffer src, Buffer dest) {
return copyToAsync(src, dest, src.getSize()); public void copyTo(Buffer src, Buffer dest) {
} copyTo(src, dest, src.getSize());
}
public ByteBuffer map(Buffer src, int size, int offset, MappingAccess access) {
throw new UnsupportedOperationException("not supported yet"); public Event copyToAsync(Buffer src, Buffer dest, int size, int srcOffset, int destOffset) {
} throw new UnsupportedOperationException("not supported yet");
public ByteBuffer map(Buffer src, int size, MappingAccess access) { }
return map(src, size, 0, access);
} public Event copyToAsync(Buffer src, Buffer dest, int size) {
public ByteBuffer map(Buffer src, MappingAccess access) { return copyToAsync(src, dest, size, 0, 0);
return map(src, src.getSize(), access); }
}
public void unmap(Buffer src, ByteBuffer ptr) { public Event copyToAsync(Buffer src, Buffer dest) {
throw new UnsupportedOperationException("not supported yet"); 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: async mapping
//TODO: clEnqueueFillBuffer //TODO: clEnqueueFillBuffer
//TODO: image read/write //TODO: image read/write
public void flush() {
public void flush() { throw new UnsupportedOperationException("not supported yet");
throw new UnsupportedOperationException("not supported yet"); }
}
public void finish() { public void finish() {
throw new UnsupportedOperationException("not supported yet"); 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. * The central OpenCL context. Every actions start from here.
*
* @author Sebastian Weiss * @author Sebastian Weiss
*/ */
public final class Context { public final class Context extends NativeCLObject {
private final long context; private final long context;
public Context(long context) { public Context(long context) {
this.context = context; this.context = context;
} }
public List<? extends Device> getDevices() { public List<? extends Device> getDevices() {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public CommandQueue createQueue() { public CommandQueue createQueue() {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
//TODO: constructor with specific device and properties //TODO: constructor with specific device and properties
public Buffer createBuffer(int size, MemoryAccess access) { public Buffer createBuffer(int size, MemoryAccess access) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public Buffer createBuffer(int size) {
return createBuffer(size, MemoryAccess.READ_WRITE); 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, MemoryAccess access) {
} throw new UnsupportedOperationException("not supported yet");
public Buffer useHostBuffer(ByteBuffer data, int size) { }
return useHostBuffer(data, size, MemoryAccess.READ_WRITE);
} public Buffer useHostBuffer(ByteBuffer data, int size) {
return useHostBuffer(data, size, MemoryAccess.READ_WRITE);
public static enum ImageChannelOrder { }
R, Rx, A,
INTENSITY, @Override
LUMINANCE, public void deleteObject() {
RG, RGx, RA, throw new UnsupportedOperationException("Not supported yet.");
RGB, RGBx, }
RGBA,
ARGB, BGRA public static enum ImageChannelOrder {
}
public static enum ImageChannelType { R, Rx, A,
SNORM_INT8, INTENSITY,
SNORM_INT16, LUMINANCE,
UNORM_INT8, RG, RGx, RA,
UNROM_INT16, RGB, RGBx,
UNORM_SHORT_565, RGBA,
UNROM_SHORT_555, ARGB, BGRA
UNORM_INT_101010, }
SIGNED_INT8,
SIGNED_INT16, public static enum ImageChannelType {
SIGNED_INT32,
UNSIGNED_INT8, SNORM_INT8,
UNSIGNED_INT16, SNORM_INT16,
UNSIGNED_INT32, UNORM_INT8,
HALF_FLOAT, UNROM_INT16,
FLOAT UNORM_SHORT_565,
} UNROM_SHORT_555,
public static class ImageFormat { //Struct UNORM_INT_101010,
public ImageChannelOrder channelOrder; SIGNED_INT8,
public ImageChannelType channelType; SIGNED_INT16,
} SIGNED_INT32,
public static enum ImageType { UNSIGNED_INT8,
IMAGE_1D, UNSIGNED_INT16,
IMAGE_1D_BUFFER, UNSIGNED_INT32,
IMAGE_2D, HALF_FLOAT,
IMAGE_3D, FLOAT
IMAGE_1D_ARRAY, }
IMAGE_2D_ARRAY
} public static class ImageFormat { //Struct
public static class ImageDescriptor { //Struct
public ImageType type; public ImageChannelOrder channelOrder;
public int width; public ImageChannelType channelType;
public int height; }
public int depth;
public int arraySize; public static enum ImageType {
public int rowPitch;
public int slicePitch; IMAGE_1D,
public int numMipLevels; IMAGE_1D_BUFFER,
public int numSamples; IMAGE_2D,
public Buffer buffer; IMAGE_3D,
} IMAGE_1D_ARRAY,
public Buffer createImage(MemoryAccess access, ImageFormat format, ImageDescriptor descr, ByteBuffer hostPtr) { IMAGE_2D_ARRAY
throw new UnsupportedOperationException("not supported yet"); }
}
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 //TODO: add simplified methods for 1D, 2D, 3D textures
//Interop //Interop
public Buffer bindVertexBuffer(VertexBuffer vb) {
public Buffer bindVertexBuffer(VertexBuffer vb) { throw new UnsupportedOperationException("not supported yet");
throw new UnsupportedOperationException("not supported yet"); }
}
public Buffer bindIndexBuffer(IndexBuffer ib) { public Buffer bindIndexBuffer(IndexBuffer ib) {
if (!(ib instanceof IndexByteBuffer) if (!(ib instanceof IndexByteBuffer)
&& !(ib instanceof IndexShortBuffer) && !(ib instanceof IndexShortBuffer)
&& !(ib instanceof IndexIntBuffer)) { && !(ib instanceof IndexIntBuffer)) {
throw new IllegalArgumentException("Index buffer must be an IndexByteBuffer, IndexShortBuffer or IndexIntBuffer"); throw new IllegalArgumentException("Index buffer must be an IndexByteBuffer, IndexShortBuffer or IndexIntBuffer");
} }
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public Buffer bindImage(Image image) {
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 createProgramFromSourceCode(String sourceCode) {
} throw new UnsupportedOperationException("not supported yet");
public Program createProgramFromSourceFilesWithInclude( }
String include, String... resources) {
//TODO: load resources public Program createProgramFromSourceFilesWithInclude(
throw new UnsupportedOperationException("not implemented yet"); String include, String... resources) {
} //TODO: load resources
public Program createProgramFormSourcesWithInclude(String include, List<String> resources) { throw new UnsupportedOperationException("not implemented yet");
return createProgramFromSourceFilesWithInclude(include, resources.toArray(new String[resources.size()])); }
}
public Program createProgramFromSources(String... resources) { public Program createProgramFormSourcesWithInclude(String include, List<String> resources) {
return createProgramFromSourceFilesWithInclude(null, resources); return createProgramFromSourceFilesWithInclude(include, resources.toArray(new String[resources.size()]));
} }
public Program createProgramFromSources(List<String> resources) {
return createProgramFormSourcesWithInclude(null, resources); 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 * @author Sebastian Weiss
*/ */
public final class Kernel { public final class Kernel extends NativeCLObject {
private final WorkSize globalWorkSize;
private final WorkSize workGroupSize; private final WorkSize globalWorkSize;
private final long kernel; private final WorkSize workGroupSize;
private final long kernel;
public Kernel(long kernel) {
this.kernel = kernel; public Kernel(long kernel) {
this.globalWorkSize = new WorkSize(0); this.kernel = kernel;
this.workGroupSize = new WorkSize(0); this.globalWorkSize = new WorkSize(0);
} this.workGroupSize = new WorkSize(0);
}
public String getName() {
throw new UnsupportedOperationException("not supported yet"); public String getName() {
} throw new UnsupportedOperationException("not supported yet");
public int getArgCount() { }
throw new UnsupportedOperationException("not supported yet");
} public int getArgCount() {
throw new UnsupportedOperationException("not supported yet");
public WorkSize getGlobalWorkSize() { }
return globalWorkSize;
} public WorkSize getGlobalWorkSize() {
public void setGlobalWorkSize(WorkSize ws) { return globalWorkSize;
globalWorkSize.set(ws); }
}
public void setGlobalWorkSize(int size) { public void setGlobalWorkSize(WorkSize ws) {
globalWorkSize.set(1, size); globalWorkSize.set(ws);
} }
public void setGlobalWorkSize(int width, int height) {
globalWorkSize.set(2, width, height); public void setGlobalWorkSize(int size) {
} globalWorkSize.set(1, size);
public void setGlobalWorkSize(int width, int height, int depth) { }
globalWorkSize.set(3, width, height, depth);
} public void setGlobalWorkSize(int width, int height) {
globalWorkSize.set(2, width, height);
public WorkSize getWorkGroupSize() { }
return workGroupSize;
} public void setGlobalWorkSize(int width, int height, int depth) {
public void setWorkGroupSize(WorkSize ws) { globalWorkSize.set(3, width, height, depth);
workGroupSize.set(ws); }
}
public void setWorkGroupSize(int size) { public WorkSize getWorkGroupSize() {
workGroupSize.set(1, size); return workGroupSize;
} }
public void setWorkGroupSize(int width, int height) {
workGroupSize.set(2, width, height); public void setWorkGroupSize(WorkSize ws) {
} workGroupSize.set(ws);
public void setWorkGroupSize(int width, int height, int depth) { }
workGroupSize.set(3, width, height, depth);
} public void setWorkGroupSize(int size) {
public void setWorkGroupSizeToNull() { workGroupSize.set(1, size);
workGroupSize.set(1, 0); }
}
public void setWorkGroupSize(int width, int height) {
public void setArg(int index, LocalMemPerElement t) { workGroupSize.set(2, width, height);
throw new UnsupportedOperationException("not supported yet"); }
}
public void setArg(int index, LocalMem t) { public void setWorkGroupSize(int width, int height, int depth) {
throw new UnsupportedOperationException("not supported yet"); workGroupSize.set(3, width, height, depth);
} }
public void setArg(int index, Buffer t) {
throw new UnsupportedOperationException("not supported yet"); public void setWorkGroupSizeToNull() {
} workGroupSize.set(1, 0);
public void setArg(int index, byte b) { }
throw new UnsupportedOperationException("not supported yet");
} public void setArg(int index, LocalMemPerElement t) {
public void setArg(int index, short s) { throw new UnsupportedOperationException("not supported yet");
throw new UnsupportedOperationException("not supported yet"); }
}
public void setArg(int index, int i) { public void setArg(int index, LocalMem t) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void setArg(int index, long l) {
throw new UnsupportedOperationException("not supported yet"); public void setArg(int index, Buffer t) {
} throw new UnsupportedOperationException("not supported yet");
public void setArg(int index, float f) { }
throw new UnsupportedOperationException("not supported yet");
} public void setArg(int index, byte b) {
public void setArg(int index, double d) { throw new UnsupportedOperationException("not supported yet");
throw new UnsupportedOperationException("not supported yet"); }
}
public void setArg(int index, Vector2f v) { public void setArg(int index, short s) {
throw new UnsupportedOperationException("not supported yet"); 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) { public void setArg(int index, int i) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void setArg(int index, Quaternion q) {
throw new UnsupportedOperationException("not supported yet"); public void setArg(int index, long l) {
} throw new UnsupportedOperationException("not supported yet");
public void setArg(int index, Object arg) { }
if (arg instanceof Byte) {
setArg(index, (byte) arg); public void setArg(int index, float f) {
} else if (arg instanceof Short) { throw new UnsupportedOperationException("not supported yet");
setArg(index, (short) arg); }
} else if (arg instanceof Integer) {
setArg(index, (int) arg); public void setArg(int index, double d) {
} else if (arg instanceof Long) { throw new UnsupportedOperationException("not supported yet");
setArg(index, (long) arg); }
} else if (arg instanceof Float) {
setArg(index, (float) arg); public void setArg(int index, Vector2f v) {
} else if (arg instanceof Double) { throw new UnsupportedOperationException("not supported yet");
setArg(index, (double) arg); }
} else if (arg instanceof Vector2f) {
setArg(index, (Vector2f) arg); //Vector3f not supported because cl_float3 is the same as a float4
} else if (arg instanceof Vector4f) {
setArg(index, (Vector4f) arg); public void setArg(int index, Vector4f v) {
} else if (arg instanceof Quaternion) { throw new UnsupportedOperationException("not supported yet");
setArg(index, (Quaternion) arg); }
} else if (arg instanceof LocalMemPerElement) {
setArg(index, (LocalMemPerElement) arg); public void setArg(int index, Quaternion q) {
} else if (arg instanceof LocalMem) { throw new UnsupportedOperationException("not supported yet");
setArg(index, (LocalMem) arg); }
} else if (arg instanceof Buffer) {
setArg(index, (Buffer) arg); public void setArg(int index, Object arg) {
} else { if (arg instanceof Byte) {
throw new IllegalArgumentException("unknown kernel argument type: "+arg); setArg(index, (byte) arg);
} } else if (arg instanceof Short) {
} setArg(index, (short) arg);
private void setArgs(Object... args) { } else if (arg instanceof Integer) {
for (int i=0; i<args.length; ++i) { setArg(index, (int) arg);
setArg(i, args[i]); } else if (arg instanceof Long) {
} setArg(index, (long) arg);
} } else if (arg instanceof Float) {
setArg(index, (float) arg);
public Event Run(CommandQueue queue) { } else if (arg instanceof Double) {
throw new UnsupportedOperationException("not supported yet"); setArg(index, (double) arg);
} } else if (arg instanceof Vector2f) {
public Event Run1(CommandQueue queue, WorkSize globalWorkSize, Object... args) { setArg(index, (Vector2f) arg);
setGlobalWorkSize(globalWorkSize); } else if (arg instanceof Vector4f) {
setWorkGroupSizeToNull(); setArg(index, (Vector4f) arg);
setArgs(args); } else if (arg instanceof Quaternion) {
return Run(queue); setArg(index, (Quaternion) arg);
} } else if (arg instanceof LocalMemPerElement) {
public Event Run2(CommandQueue queue, WorkSize globalWorkSize, setArg(index, (LocalMemPerElement) arg);
WorkSize workGroupSize, Object... args) { } else if (arg instanceof LocalMem) {
setGlobalWorkSize(globalWorkSize); setArg(index, (LocalMem) arg);
setWorkGroupSize(workGroupSize); } else if (arg instanceof Buffer) {
setArgs(args); setArg(index, (Buffer) arg);
return Run(queue); } 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("GammaCorrection", false);
defaults.put("Resizable", false); defaults.put("Resizable", false);
defaults.put("SwapBuffers", true); 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() { public boolean isSwapBuffers() {
return getBoolean("SwapBuffers"); 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(); 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. * @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.TouchInput;
import com.jme3.input.dummy.DummyKeyInput; import com.jme3.input.dummy.DummyKeyInput;
import com.jme3.input.dummy.DummyMouseInput; import com.jme3.input.dummy.DummyMouseInput;
import com.jme3.opencl.Context;
import com.jme3.renderer.Renderer; import com.jme3.renderer.Renderer;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level; 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 return true; // Doesn't really matter if true or false. Either way
// RenderManager won't render anything. // 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.TouchInput;
import com.jme3.input.awt.AwtKeyInput; import com.jme3.input.awt.AwtKeyInput;
import com.jme3.input.awt.AwtMouseInput; import com.jme3.input.awt.AwtMouseInput;
import com.jme3.opencl.Context;
import com.jme3.renderer.Renderer; import com.jme3.renderer.Renderer;
import com.jme3.system.*; import com.jme3.system.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -145,6 +146,11 @@ public class AwtPanelsContext implements JmeContext {
return actualContext != null && actualContext.isRenderable(); return actualContext != null && actualContext.isRenderable();
} }
@Override
public Context getOpenCLContext() {
return actualContext.getOpenCLContext();
}
public AwtPanelsContext(){ 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.JoyInput;
import com.jme3.input.KeyInput; import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput; import com.jme3.input.MouseInput;
import com.jme3.opencl.Context;
import com.jme3.renderer.Renderer; import com.jme3.renderer.Renderer;
import com.jme3.renderer.RendererException; import com.jme3.renderer.RendererException;
import com.jme3.renderer.jogl.JoglGL; import com.jme3.renderer.jogl.JoglGL;
@ -84,6 +85,8 @@ public abstract class JoglContext implements JmeContext {
protected MouseInput mouseInput; protected MouseInput mouseInput;
protected JoyInput joyInput; protected JoyInput joyInput;
protected com.jme3.opencl.Context clContext;
@Override @Override
public void setSystemListener(SystemListener listener){ public void setSystemListener(SystemListener listener){
this.listener = listener; this.listener = listener;
@ -209,6 +212,14 @@ public abstract class JoglContext implements JmeContext {
if (joyInput != null) { if (joyInput != null) {
joyInput.initialize(); joyInput.initialize();
} }
if (settings.isOpenCLSupport()) {
initOpenCL();
}
}
protected void initOpenCL() {
logger.info("Initialize OpenCL with JOGL");
} }
public void internalCreate() { public void internalCreate() {
@ -266,4 +277,10 @@ public abstract class JoglContext implements JmeContext {
} }
return samples; 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.JInputJoyInput;
import com.jme3.input.lwjgl.LwjglKeyInput; import com.jme3.input.lwjgl.LwjglKeyInput;
import com.jme3.input.lwjgl.LwjglMouseInput; import com.jme3.input.lwjgl.LwjglMouseInput;
import com.jme3.opencl.lwjgl.LwjglCL;
import com.jme3.renderer.Renderer; import com.jme3.renderer.Renderer;
import com.jme3.renderer.RendererException; import com.jme3.renderer.RendererException;
import com.jme3.renderer.lwjgl.LwjglGL; 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.renderer.opengl.GLTracer;
import com.jme3.system.*; import com.jme3.system.*;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLException;
import org.lwjgl.Sys; import org.lwjgl.Sys;
import org.lwjgl.opencl.CL;
import org.lwjgl.opencl.CL10;
import org.lwjgl.opencl.CLPlatform;
import org.lwjgl.opengl.*; import org.lwjgl.opengl.*;
/** /**
@ -81,6 +87,10 @@ public abstract class LwjglContext implements JmeContext {
protected JInputJoyInput joyInput; protected JInputJoyInput joyInput;
protected Timer timer; protected Timer timer;
protected SystemListener listener; protected SystemListener listener;
protected LwjglCL clImpl;
protected CLPlatform clPlatform;
protected com.jme3.opencl.Context context;
public void setSystemListener(SystemListener listener) { public void setSystemListener(SystemListener listener) {
this.listener = listener; this.listener = listener;
@ -245,8 +255,47 @@ public abstract class LwjglContext implements JmeContext {
if (joyInput != null) { if (joyInput != null) {
joyInput.initialize(); 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() { public void internalDestroy() {
renderer = null; renderer = null;
timer = null; timer = null;
@ -311,4 +360,8 @@ public abstract class LwjglContext implements JmeContext {
return timer; 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); GL11.glEnable(ARBMultisample.GL_MULTISAMPLE_ARB);
} }
} }
if (settings.isOpenCLSupport()) {
initOpenCL();
}
} }
protected void destroyContext(){ protected void destroyContext(){

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

Loading…
Cancel
Save