aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-02-01 01:15:31 +0100
committerMichael Bien <[email protected]>2010-02-01 01:15:31 +0100
commit3394fc5b25927ae8733cab867ec1caf682cd4618 (patch)
tree8b216537ccc1aa5caf7cd9b9e8cfd3defaed642a
parentbb14ae720b21eeae5030623bf77ed7e173dca936 (diff)
glDeleteBuffers and other minor improvements.
-rw-r--r--src/com/mbien/opencl/demos/fractal/MultiDeviceFractal.java36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/com/mbien/opencl/demos/fractal/MultiDeviceFractal.java b/src/com/mbien/opencl/demos/fractal/MultiDeviceFractal.java
index 0e1a250..01e1574 100644
--- a/src/com/mbien/opencl/demos/fractal/MultiDeviceFractal.java
+++ b/src/com/mbien/opencl/demos/fractal/MultiDeviceFractal.java
@@ -65,7 +65,7 @@ public class MultiDeviceFractal implements GLEventListener {
private CLCommandQueue[] queues;
private CLKernel[] kernels;
private CLEventList probes;
- private CLGLBuffer<IntBuffer>[] pboBuffers;
+ private CLGLBuffer<?>[] pboBuffers;
private int width = 0;
private int height = 0;
@@ -208,10 +208,20 @@ public class MultiDeviceFractal implements GLEventListener {
@SuppressWarnings("unchecked")
private void initPBO(GL gl) {
- pboBuffers = new CLGLBuffer[kernels.length];
+ if(pboBuffers != null) {
+ int[] oldPbos = new int[pboBuffers.length];
+ for (int i = 0; i < pboBuffers.length; i++) {
+ CLGLBuffer<?> buffer = pboBuffers[i];
+ oldPbos[i] = buffer.GLID;
+ buffer.release();
+ }
+ gl.glDeleteBuffers(oldPbos.length, oldPbos, 0);
+ }
+
+ pboBuffers = new CLGLBuffer[slices];
- int[] pbo = new int[pboBuffers.length];
- gl.glGenBuffers(pboBuffers.length, pbo, 0);
+ int[] pbo = new int[slices];
+ gl.glGenBuffers(slices, pbo, 0);
// setup one empty PBO per slice
for (int i = 0; i < slices; i++) {
@@ -227,11 +237,15 @@ public class MultiDeviceFractal implements GLEventListener {
}
public void display(GLAutoDrawable drawable) {
+ GL gl = drawable.getGL();
if(!initialized) {
- initPBO(drawable.getGL());
+ initPBO(gl);
}
+ // make sure GL does not use our objects before we start computeing
+ gl.glFinish();
compute();
- render(drawable.getGL().getGL2());
+
+ render(gl.getGL2());
}
// OpenCL
@@ -244,6 +258,7 @@ public class MultiDeviceFractal implements GLEventListener {
// release all old events, you can't reuse events in OpenCL
probes.release();
+ // start computation
for (int i = 0; i < slices; i++) {
kernels[i].putArg(pboBuffers[i])
@@ -259,6 +274,11 @@ public class MultiDeviceFractal implements GLEventListener {
}
+ // block until done
+ for (int i = 0; i < slices; i++) {
+ queues[i].finish();
+ }
+
}
// OpenGL
@@ -302,10 +322,6 @@ public class MultiDeviceFractal implements GLEventListener {
this.width = width;
this.height = height;
- for (CLGLBuffer<IntBuffer> buffer : pboBuffers) {
- buffer.release();
- }
-
initPBO(drawable.getGL());
initView(drawable.getGL().getGL2(), drawable.getWidth(), drawable.getHeight());
}