started with context creation

define_list_fix
shamanDevel 9 years ago
parent 195a5a69be
commit bb15931fa2
  1. 29
      jme3-core/src/main/java/com/jme3/opencl/CL.java
  2. 27
      jme3-core/src/main/java/com/jme3/opencl/CommandQueue.java
  3. 27
      jme3-core/src/main/java/com/jme3/opencl/Context.java
  4. 34
      jme3-core/src/main/java/com/jme3/opencl/Kernel.java
  5. 50
      jme3-core/src/main/java/com/jme3/opencl/NativeCLObject.java
  6. 14
      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,12 +35,14 @@ 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
*/ */
@ -76,8 +78,10 @@ public interface CL {
this.b16d = b16.asDoubleBuffer(); this.b16d = b16.asDoubleBuffer();
} }
} }
/** /**
* Returns up to 4 temp buffer instances * Returns up to 4 temp buffer instances
*
* @return * @return
*/ */
TempBuffer[] getTempBuffers(); TempBuffer[] getTempBuffers();
@ -87,44 +91,64 @@ public interface CL {
//OpenCL functions //OpenCL functions
long clCreateCommandQueue(long context, long device, boolean profiling); long clCreateCommandQueue(long context, long device, boolean profiling);
void clReleaseCommandQueue(long queue); void clReleaseCommandQueue(long queue);
long clCreateBuffer(long context, MemoryAccess access, int size, ByteBuffer hostPtr); 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 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 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 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 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 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); long clCreateImage(long context, MemoryAccess access, Context.ImageFormat format, Context.ImageDescriptor desc, ByteBuffer ptr);
Context.ImageFormat[] clGetSupportedImageFormats(long context, MemoryAccess ma, Context.ImageType type); 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 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 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 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 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 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 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); 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); long clEnqueueUnmapMemObject(long queue, long mem, ByteBuffer ptr);
int getMemSize(long mem); //uses clGetMemObjectInfo int getMemSize(long mem); //uses clGetMemObjectInfo
long clCreateProgramWithSource(long context, CharSequence[] sources); long clCreateProgramWithSource(long context, CharSequence[] sources);
//TODO: create from binary //TODO: create from binary
long clReleaseProgram(long program); long clReleaseProgram(long program);
void clBuildProgram(long program, long[] devices, CharSequence optpions) throws KernelCompilationException; void clBuildProgram(long program, long[] devices, CharSequence optpions) throws KernelCompilationException;
String getKernelNames(long program); //uses clGetProgramInfo String getKernelNames(long program); //uses clGetProgramInfo
long clCreateKernel(long program, String kernelName); long clCreateKernel(long program, String kernelName);
void clReleaseKernel(long kernel); void clReleaseKernel(long kernel);
void clSetKernelArg(long kernel, int argIndex, int argSize, ByteBuffer argValue); void clSetKernelArg(long kernel, int argIndex, int argSize, ByteBuffer argValue);
String getKernelName(long kernel); //uses clGetKernelInfo String getKernelName(long kernel); //uses clGetKernelInfo
int getKernelNumArgs(long kernel); //uses clGetKernelInfo int getKernelNumArgs(long kernel); //uses clGetKernelInfo
//TODO: clGetKernelWorkGroupInfo //TODO: clGetKernelWorkGroupInfo
@ -132,12 +156,15 @@ public interface CL {
ByteBuffer globalWorkOffset, ByteBuffer globalWorkSize, ByteBuffer localWorkSize); ByteBuffer globalWorkOffset, ByteBuffer globalWorkSize, ByteBuffer localWorkSize);
void clWaitForEvents(long[] events); void clWaitForEvents(long[] events);
void clWaitForEvent(long event); void clWaitForEvent(long event);
boolean isEventCompleted(long event); //uses clGetEventInfo boolean isEventCompleted(long event); //uses clGetEventInfo
void clReleaseEvent(long event); void clReleaseEvent(long event);
void clFlush(long queue); void clFlush(long queue);
void clFinish(long queue);
void clFinish(long queue);
} }

@ -37,7 +37,8 @@ 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) { public CommandQueue(long queue) {
@ -47,9 +48,11 @@ public final class CommandQueue {
public void read(Buffer src, ByteBuffer dest, int size, int offset) { public void read(Buffer src, ByteBuffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void read(Buffer src, ByteBuffer dest, int size) { public void read(Buffer src, ByteBuffer dest, int size) {
read(src, dest, size, 0); read(src, dest, size, 0);
} }
public void read(Buffer src, ByteBuffer dest) { public void read(Buffer src, ByteBuffer dest) {
read(src, dest, src.getSize(), 0); read(src, dest, src.getSize(), 0);
} }
@ -57,9 +60,11 @@ public final class CommandQueue {
public Event readAsync(Buffer src, ByteBuffer dest, int size, int offset) { public Event readAsync(Buffer src, ByteBuffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public Event readAsync(Buffer src, ByteBuffer dest, int size) { public Event readAsync(Buffer src, ByteBuffer dest, int size) {
return readAsync(src, dest, size, 0); return readAsync(src, dest, size, 0);
} }
public Event readAsync(Buffer src, ByteBuffer dest) { public Event readAsync(Buffer src, ByteBuffer dest) {
return readAsync(src, dest, src.getSize()); return readAsync(src, dest, src.getSize());
} }
@ -67,9 +72,11 @@ public final class CommandQueue {
public void write(ByteBuffer src, Buffer dest, int size, int offset) { public void write(ByteBuffer src, Buffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void write(ByteBuffer src, Buffer dest, int size) { public void write(ByteBuffer src, Buffer dest, int size) {
write(src, dest, size, 0); write(src, dest, size, 0);
} }
public void write(ByteBuffer src, Buffer dest) { public void write(ByteBuffer src, Buffer dest) {
write(src, dest, dest.getSize()); write(src, dest, dest.getSize());
} }
@ -77,9 +84,11 @@ public final class CommandQueue {
public Event writeAsync(ByteBuffer src, Buffer dest, int size, int offset) { public Event writeAsync(ByteBuffer src, Buffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public Event writeAsync(ByteBuffer src, Buffer dest, int size) { public Event writeAsync(ByteBuffer src, Buffer dest, int size) {
return writeAsync(src, dest, size, 0); return writeAsync(src, dest, size, 0);
} }
public Event writeAsync(ByteBuffer src, Buffer dest) { public Event writeAsync(ByteBuffer src, Buffer dest) {
return writeAsync(src, dest, dest.getSize()); return writeAsync(src, dest, dest.getSize());
} }
@ -87,9 +96,11 @@ public final class CommandQueue {
public void copyTo(Buffer src, Buffer dest, int size, int srcOffset, int destOffset) { public void copyTo(Buffer src, Buffer dest, int size, int srcOffset, int destOffset) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void copyTo(Buffer src, Buffer dest, int size) { public void copyTo(Buffer src, Buffer dest, int size) {
copyTo(src, dest, size, 0, 0); copyTo(src, dest, size, 0, 0);
} }
public void copyTo(Buffer src, Buffer dest) { public void copyTo(Buffer src, Buffer dest) {
copyTo(src, dest, src.getSize()); copyTo(src, dest, src.getSize());
} }
@ -97,9 +108,11 @@ public final class CommandQueue {
public Event copyToAsync(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 Event copyToAsync(Buffer src, Buffer dest, int size) {
return copyToAsync(src, dest, size, 0, 0); return copyToAsync(src, dest, size, 0, 0);
} }
public Event copyToAsync(Buffer src, Buffer dest) { public Event copyToAsync(Buffer src, Buffer dest) {
return copyToAsync(src, dest, src.getSize()); return copyToAsync(src, dest, src.getSize());
} }
@ -107,27 +120,33 @@ public final class CommandQueue {
public ByteBuffer map(Buffer src, int size, int offset, MappingAccess access) { public ByteBuffer map(Buffer src, int size, int offset, MappingAccess access) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public ByteBuffer map(Buffer src, int size, MappingAccess access) { public ByteBuffer map(Buffer src, int size, MappingAccess access) {
return map(src, size, 0, access); return map(src, size, 0, access);
} }
public ByteBuffer map(Buffer src, MappingAccess access) { public ByteBuffer map(Buffer src, MappingAccess access) {
return map(src, src.getSize(), access); return map(src, src.getSize(), access);
} }
public void unmap(Buffer src, ByteBuffer ptr) { public void unmap(Buffer src, ByteBuffer ptr) {
throw new UnsupportedOperationException("not supported yet"); 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,9 +42,10 @@ 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;
@ -64,6 +65,7 @@ public final class Context {
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) { public Buffer createBuffer(int size) {
return createBuffer(size, MemoryAccess.READ_WRITE); return createBuffer(size, MemoryAccess.READ_WRITE);
} }
@ -71,11 +73,18 @@ public final class Context {
public Buffer useHostBuffer(ByteBuffer data, int size, MemoryAccess access) { public Buffer useHostBuffer(ByteBuffer data, int size, MemoryAccess access) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public Buffer useHostBuffer(ByteBuffer data, int size) { public Buffer useHostBuffer(ByteBuffer data, int size) {
return useHostBuffer(data, size, MemoryAccess.READ_WRITE); return useHostBuffer(data, size, MemoryAccess.READ_WRITE);
} }
@Override
public void deleteObject() {
throw new UnsupportedOperationException("Not supported yet.");
}
public static enum ImageChannelOrder { public static enum ImageChannelOrder {
R, Rx, A, R, Rx, A,
INTENSITY, INTENSITY,
LUMINANCE, LUMINANCE,
@ -84,7 +93,9 @@ public final class Context {
RGBA, RGBA,
ARGB, BGRA ARGB, BGRA
} }
public static enum ImageChannelType { public static enum ImageChannelType {
SNORM_INT8, SNORM_INT8,
SNORM_INT16, SNORM_INT16,
UNORM_INT8, UNORM_INT8,
@ -101,11 +112,15 @@ public final class Context {
HALF_FLOAT, HALF_FLOAT,
FLOAT FLOAT
} }
public static class ImageFormat { //Struct public static class ImageFormat { //Struct
public ImageChannelOrder channelOrder; public ImageChannelOrder channelOrder;
public ImageChannelType channelType; public ImageChannelType channelType;
} }
public static enum ImageType { public static enum ImageType {
IMAGE_1D, IMAGE_1D,
IMAGE_1D_BUFFER, IMAGE_1D_BUFFER,
IMAGE_2D, IMAGE_2D,
@ -113,7 +128,9 @@ public final class Context {
IMAGE_1D_ARRAY, IMAGE_1D_ARRAY,
IMAGE_2D_ARRAY IMAGE_2D_ARRAY
} }
public static class ImageDescriptor { //Struct public static class ImageDescriptor { //Struct
public ImageType type; public ImageType type;
public int width; public int width;
public int height; public int height;
@ -125,16 +142,17 @@ public final class Context {
public int numSamples; public int numSamples;
public Buffer buffer; public Buffer buffer;
} }
public Buffer createImage(MemoryAccess access, ImageFormat format, ImageDescriptor descr, ByteBuffer hostPtr) { public Buffer createImage(MemoryAccess access, ImageFormat format, ImageDescriptor descr, ByteBuffer hostPtr) {
throw new UnsupportedOperationException("not supported yet"); 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)
@ -143,6 +161,7 @@ public final class Context {
} }
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public Buffer bindImage(Image image) { public Buffer bindImage(Image image) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
@ -150,17 +169,21 @@ public final class Context {
public Program createProgramFromSourceCode(String sourceCode) { public Program createProgramFromSourceCode(String sourceCode) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public Program createProgramFromSourceFilesWithInclude( public Program createProgramFromSourceFilesWithInclude(
String include, String... resources) { String include, String... resources) {
//TODO: load resources //TODO: load resources
throw new UnsupportedOperationException("not implemented yet"); throw new UnsupportedOperationException("not implemented yet");
} }
public Program createProgramFormSourcesWithInclude(String include, List<String> resources) { public Program createProgramFormSourcesWithInclude(String include, List<String> resources) {
return createProgramFromSourceFilesWithInclude(include, resources.toArray(new String[resources.size()])); return createProgramFromSourceFilesWithInclude(include, resources.toArray(new String[resources.size()]));
} }
public Program createProgramFromSources(String... resources) { public Program createProgramFromSources(String... resources) {
return createProgramFromSourceFilesWithInclude(null, resources); return createProgramFromSourceFilesWithInclude(null, resources);
} }
public Program createProgramFromSources(List<String> resources) { public Program createProgramFromSources(List<String> resources) {
return createProgramFormSourcesWithInclude(null, resources); return createProgramFormSourcesWithInclude(null, resources);
} }

@ -39,7 +39,8 @@ 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 globalWorkSize;
private final WorkSize workGroupSize; private final WorkSize workGroupSize;
private final long kernel; private final long kernel;
@ -53,6 +54,7 @@ public final class Kernel {
public String getName() { public String getName() {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public int getArgCount() { public int getArgCount() {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
@ -60,15 +62,19 @@ public final class Kernel {
public WorkSize getGlobalWorkSize() { public WorkSize getGlobalWorkSize() {
return globalWorkSize; return globalWorkSize;
} }
public void setGlobalWorkSize(WorkSize ws) { public void setGlobalWorkSize(WorkSize ws) {
globalWorkSize.set(ws); globalWorkSize.set(ws);
} }
public void setGlobalWorkSize(int size) { public void setGlobalWorkSize(int size) {
globalWorkSize.set(1, size); globalWorkSize.set(1, size);
} }
public void setGlobalWorkSize(int width, int height) { public void setGlobalWorkSize(int width, int height) {
globalWorkSize.set(2, width, height); globalWorkSize.set(2, width, height);
} }
public void setGlobalWorkSize(int width, int height, int depth) { public void setGlobalWorkSize(int width, int height, int depth) {
globalWorkSize.set(3, width, height, depth); globalWorkSize.set(3, width, height, depth);
} }
@ -76,18 +82,23 @@ public final class Kernel {
public WorkSize getWorkGroupSize() { public WorkSize getWorkGroupSize() {
return workGroupSize; return workGroupSize;
} }
public void setWorkGroupSize(WorkSize ws) { public void setWorkGroupSize(WorkSize ws) {
workGroupSize.set(ws); workGroupSize.set(ws);
} }
public void setWorkGroupSize(int size) { public void setWorkGroupSize(int size) {
workGroupSize.set(1, size); workGroupSize.set(1, size);
} }
public void setWorkGroupSize(int width, int height) { public void setWorkGroupSize(int width, int height) {
workGroupSize.set(2, width, height); workGroupSize.set(2, width, height);
} }
public void setWorkGroupSize(int width, int height, int depth) { public void setWorkGroupSize(int width, int height, int depth) {
workGroupSize.set(3, width, height, depth); workGroupSize.set(3, width, height, depth);
} }
public void setWorkGroupSizeToNull() { public void setWorkGroupSizeToNull() {
workGroupSize.set(1, 0); workGroupSize.set(1, 0);
} }
@ -95,40 +106,53 @@ public final class Kernel {
public void setArg(int index, LocalMemPerElement t) { public void setArg(int index, LocalMemPerElement t) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void setArg(int index, LocalMem t) { public void setArg(int index, LocalMem t) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void setArg(int index, Buffer t) { public void setArg(int index, Buffer t) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void setArg(int index, byte b) { public void setArg(int index, byte b) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void setArg(int index, short s) { 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, int i) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void setArg(int index, long l) { public void setArg(int index, long l) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void setArg(int index, float f) { public void setArg(int index, float f) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void setArg(int index, double d) { 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, Vector2f v) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
//Vector3f not supported because cl_float3 is the same as a float4 //Vector3f not supported because cl_float3 is the same as a float4
public void setArg(int index, Vector4f v) { public void setArg(int index, Vector4f v) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void setArg(int index, Quaternion q) { public void setArg(int index, Quaternion q) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public void setArg(int index, Object arg) { public void setArg(int index, Object arg) {
if (arg instanceof Byte) { if (arg instanceof Byte) {
setArg(index, (byte) arg); setArg(index, (byte) arg);
@ -158,6 +182,7 @@ public final class Kernel {
throw new IllegalArgumentException("unknown kernel argument type: " + arg); throw new IllegalArgumentException("unknown kernel argument type: " + arg);
} }
} }
private void setArgs(Object... args) { private void setArgs(Object... args) {
for (int i = 0; i < args.length; ++i) { for (int i = 0; i < args.length; ++i) {
setArg(i, args[i]); setArg(i, args[i]);
@ -167,12 +192,14 @@ public final class Kernel {
public Event Run(CommandQueue queue) { public Event Run(CommandQueue queue) {
throw new UnsupportedOperationException("not supported yet"); throw new UnsupportedOperationException("not supported yet");
} }
public Event Run1(CommandQueue queue, WorkSize globalWorkSize, Object... args) { public Event Run1(CommandQueue queue, WorkSize globalWorkSize, Object... args) {
setGlobalWorkSize(globalWorkSize); setGlobalWorkSize(globalWorkSize);
setWorkGroupSizeToNull(); setWorkGroupSizeToNull();
setArgs(args); setArgs(args);
return Run(queue); return Run(queue);
} }
public Event Run2(CommandQueue queue, WorkSize globalWorkSize, public Event Run2(CommandQueue queue, WorkSize globalWorkSize,
WorkSize workGroupSize, Object... args) { WorkSize workGroupSize, Object... args) {
setGlobalWorkSize(globalWorkSize); setGlobalWorkSize(globalWorkSize);
@ -180,4 +207,9 @@ public final class Kernel {
setArgs(args); setArgs(args);
return Run(queue); 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,6 +160,7 @@ 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("OpenCL", false);
// defaults.put("Icons", null); // 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.*;
/** /**
@ -82,6 +88,10 @@ public abstract class LwjglContext implements JmeContext {
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,6 +255,45 @@ 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() {
@ -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;
@ -78,6 +81,9 @@ public abstract class LwjglContext implements JmeContext {
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