Permalink
Browse files

OpenCLObject.register() now returns this.

This allows to chain the register method like kernel=program.createKernel("ScaleKernel").register(); or testBuffer=clContext.createBuffer(1024).register();
  • Loading branch information...
shamanDevel committed Jun 19, 2016
1 parent 46db6d9 commit a8d77a7cd18d5a390efc0315e971b231306d020f
@@ -43,8 +43,9 @@ protected AbstractOpenCLObject(ObjectReleaser releaser) {
this.releaser = releaser;
}
@Override
public void register() {
public AbstractOpenCLObject register() {
OpenCLObjectManager.getInstance().registerObject(this);
return this;
}
@Override
public void release() {
@@ -52,6 +52,12 @@
protected Buffer(ObjectReleaser releaser) {
super(releaser);
}
@Override
public Buffer register() {
super.register();
return this;
}
/**
* @return the size of the buffer in bytes.
@@ -51,6 +51,12 @@ protected CommandQueue(ObjectReleaser releaser, Device device) {
this.device = device;
}
@Override
public CommandQueue register() {
super.register();
return this;
}
/**
* Returns the device associated with this command queue.
* It can be used to query properties of the device that is used to execute
@@ -72,6 +72,12 @@ protected Context(ObjectReleaser releaser) {
super(releaser);
}
@Override
public Context register() {
super.register();
return this;
}
/**
* Returns all available devices for this context.
* These devices all belong to the same {@link Platform}.
@@ -43,6 +43,12 @@
protected Event(ObjectReleaser releaser) {
super(releaser);
}
@Override
public Event register() {
super.register();
return this;
}
/**
* Waits until the action has finished (blocking).
@@ -249,7 +249,13 @@ public String toString() {
protected Image(ObjectReleaser releaser) {
super(releaser);
}
@Override
public Image register() {
super.register();
return this;
}
/**
* @return the width of the image
*/
@@ -97,6 +97,12 @@ protected Kernel(ObjectReleaser releaser) {
this.workGroupSize = new WorkSize(0);
}
@Override
public Kernel register() {
super.register();
return this;
}
/**
* @return the name of the kernel as defined in the program source code
*/
@@ -61,6 +61,7 @@
ObjectReleaser getReleaser();
/**
* Releases this native object.
*
* Should delegate to {@code getReleaser().release()}.
*/
void release();
@@ -70,6 +71,10 @@
* {@link OpenCLObjectManager}, you have to release it manually
* by calling {@link #release() }.
* Without registering or releasing, a memory leak might occur.
* <br>
* Returns {@code this} to allow calls like
* {@code Buffer buffer = clContext.createBuffer(1024).register();}.
* @return {@code this}
*/
void register();
OpenCLObject register();
}
@@ -49,6 +49,12 @@
protected Program(ObjectReleaser releaser) {
super(releaser);
}
@Override
public Program register() {
super.register();
return this;
}
/**
* Builds this program with the specified argument string on the specified
@@ -131,8 +131,7 @@ private void updateInfos() {
if (testBuffer == null && clContext != null && !bufferCreated) {
try {
testBuffer = clContext.createBuffer(1024);
testBuffer.register();
testBuffer = clContext.createBuffer(1024).register();
LOG.info("Test buffer created");
} catch (OpenCLException ex) {
LOG.log(Level.SEVERE, "Unable to create buffer", ex);
@@ -115,8 +115,7 @@ public void simpleUpdate(float tpf) {
private void initOpenCL1() {
clContext = context.getOpenCLContext();
Device device = clContext.getDevices().get(0);
clQueue = clContext.createQueue(device);
clQueue.register();
clQueue = clContext.createQueue(device).register();
//create kernel
Program program = null;
File tmpFolder = JmeSystem.getStorageFolder();
@@ -156,15 +155,13 @@ private void initOpenCL1() {
}
LOG.info("create new program from sources");
}
program.register();
kernel = program.createKernel("ScaleKernel");
kernel.register();
program.register();
kernel = program.createKernel("ScaleKernel").register();
}
private void initOpenCL2() {
//bind vertex buffer to OpenCL
VertexBuffer vb = geom.getMesh().getBuffer(VertexBuffer.Type.Position);
buffer = clContext.bindVertexBuffer(vb, MemoryAccess.READ_WRITE);
buffer.register();
buffer = clContext.bindVertexBuffer(vb, MemoryAccess.READ_WRITE).register();
ws = new com.jme3.opencl.Kernel.WorkSize(geom.getMesh().getVertexCount());
}
private void updateOpenCL(float tpf) {
@@ -122,8 +122,7 @@ public void simpleUpdate(float tpf) {
private void initOpenCL1() {
clContext = context.getOpenCLContext();
clQueue = clContext.createQueue();
clQueue.register();
clQueue = clContext.createQueue().register();
programCache = new ProgramCache(clContext);
//create kernel
String cacheID = getClass().getName()+".Julia";
@@ -135,14 +134,12 @@ private void initOpenCL1() {
programCache.saveToCache(cacheID, program);
}
program.register();
kernel = program.createKernel("JuliaSet");
kernel.register();
kernel = program.createKernel("JuliaSet").register();
C = new Vector2f(0.12f, -0.2f);
}
private void initOpenCL2() {
//bind image to OpenCL
texCL = clContext.bindImage(tex, MemoryAccess.WRITE_ONLY);
texCL.register();
texCL = clContext.bindImage(tex, MemoryAccess.WRITE_ONLY).register();
}
private void updateOpenCL(float tpf) {
//aquire resource

0 comments on commit a8d77a7

Please sign in to comment.