summaryrefslogtreecommitdiffstats
path: root/src/com/jogamp/opencl/demos/julia3d
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2011-02-04 01:02:06 +0100
committerMichael Bien <[email protected]>2011-02-04 01:02:06 +0100
commit18d1f903dc7cb436956e4f0c09cfb0ce0278bafa (patch)
treeb6d71dd9c51cf9e5bdd5b7524a6d8df4873c5881 /src/com/jogamp/opencl/demos/julia3d
parentdbe93d1e40a7bc9fbea7c5be3d59bf84e8a20ecb (diff)
- fixed bug in julia3d demo when epsilon is 0
- better device choice - cleanup
Diffstat (limited to 'src/com/jogamp/opencl/demos/julia3d')
-rw-r--r--src/com/jogamp/opencl/demos/julia3d/Julia3d.java35
-rw-r--r--src/com/jogamp/opencl/demos/julia3d/Renderer.java29
-rw-r--r--src/com/jogamp/opencl/demos/julia3d/UserSceneController.java2
3 files changed, 39 insertions, 27 deletions
diff --git a/src/com/jogamp/opencl/demos/julia3d/Julia3d.java b/src/com/jogamp/opencl/demos/julia3d/Julia3d.java
index 9f032cf..45bf706 100644
--- a/src/com/jogamp/opencl/demos/julia3d/Julia3d.java
+++ b/src/com/jogamp/opencl/demos/julia3d/Julia3d.java
@@ -1,5 +1,10 @@
package com.jogamp.opencl.demos.julia3d;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.Canvas;
+import java.awt.Dimension;
+import javax.swing.JFrame;
import com.jogamp.opencl.CLBuffer;
import com.jogamp.opencl.CLCommandQueue;
import com.jogamp.opencl.CLContext;
@@ -17,6 +22,8 @@ import java.nio.FloatBuffer;
import javax.media.opengl.GLProfile;
import javax.swing.SwingUtilities;
+import static com.jogamp.opencl.CLDevice.Type.*;
+import static com.jogamp.opencl.util.CLPlatformFilters.*;
import static com.jogamp.opencl.CLMemory.Mem.*;
import static com.jogamp.opencl.CLProgram.CompilerOptions.*;
import static com.jogamp.opencl.demos.julia3d.UserSceneController.*;
@@ -45,13 +52,13 @@ public class Julia3d {
updateCamera();
//setup, prefere GPUs
- CLDevice device = CLPlatform.getDefault().getMaxFlopsDevice(CLDevice.Type.GPU);
+ CLDevice device = CLPlatform.getDefault(type(GPU)).getMaxFlopsDevice();
if(device == null) {
device = CLPlatform.getDefault().getMaxFlopsDevice();
}
context = CLContext.create(device);
- workGroupSize = 256;
+ workGroupSize = Math.min(256, device.getMaxWorkGroupSize());
//allocate buffers
configBuffer = context.createBuffer(config.getBuffer(), READ_ONLY);
@@ -189,8 +196,10 @@ public class Julia3d {
public static void main(String[] args) {
+
GLProfile.initSingleton(true);
- RenderingConfig config = RenderingConfig.create()
+
+ final RenderingConfig config = RenderingConfig.create()
.setWidth(640).setHeight(480)
.setEnableShadow(1)
.setSuperSamplingSize(2)
@@ -207,7 +216,25 @@ public class Julia3d {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
- new Renderer(julia3d);
+
+ Renderer renderer = new Renderer(julia3d);
+ CLDevice device = julia3d.getDevice();
+
+ JFrame frame = new JFrame("Java OpenCL - Julia3D "+device.getType()+" "+device.getName());
+ frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ frame.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosed(WindowEvent e) {
+ julia3d.release();
+ System.exit(0);
+ }
+ });
+ Canvas canvas = renderer.getCanvas();
+ canvas.setPreferredSize(new Dimension(config.getWidth(), config.getHeight()));
+ frame.add(canvas);
+ frame.pack();
+ frame.setVisible(true);
+
}
});
}
diff --git a/src/com/jogamp/opencl/demos/julia3d/Renderer.java b/src/com/jogamp/opencl/demos/julia3d/Renderer.java
index 6fe2309..4713b2d 100644
--- a/src/com/jogamp/opencl/demos/julia3d/Renderer.java
+++ b/src/com/jogamp/opencl/demos/julia3d/Renderer.java
@@ -1,13 +1,9 @@
package com.jogamp.opencl.demos.julia3d;
-import com.jogamp.opencl.CLDevice;
import com.jogamp.opencl.demos.julia3d.structs.RenderingConfig;
import com.jogamp.opengl.util.awt.TextRenderer;
-import java.awt.Dimension;
+import java.awt.Canvas;
import java.awt.Font;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
import java.nio.FloatBuffer;
import java.util.Timer;
import java.util.TimerTask;
@@ -17,7 +13,6 @@ import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
-import javax.swing.JFrame;
import static com.jogamp.common.nio.Buffers.*;
import static javax.media.opengl.GL2.*;
@@ -42,6 +37,7 @@ public class Renderer implements GLEventListener {
private final Timer timer;
public Renderer(final Julia3d julia3d) {
+
this.julia3d = julia3d;
this.config = julia3d.config;
@@ -55,23 +51,8 @@ public class Renderer implements GLEventListener {
usi = new UserSceneController();
usi.init(this, canvas, config);
- CLDevice device = julia3d.getDevice();
- JFrame frame = new JFrame("Java OpenCL - Julia3D "+device.getType()+" "+device.getName());
- frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- frame.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosed(WindowEvent e) {
- julia3d.release();
- System.exit(0);
- }
- });
- canvas.setPreferredSize(new Dimension(config.getWidth(), config.getHeight()));
- frame.add(canvas);
- frame.pack();
-
- textRenderer = new TextRenderer(frame.getFont().deriveFont(Font.BOLD, 14), true, true, null, false);
+ textRenderer = new TextRenderer(new Font("Helvetica", Font.BOLD, 14), true, true, null, false);
- frame.setVisible(true);
}
public void init(GLAutoDrawable drawable) {
@@ -211,5 +192,9 @@ public class Renderer implements GLEventListener {
public void dispose(GLAutoDrawable drawable) {
}
+ public Canvas getCanvas() {
+ return canvas;
+ }
+
}
diff --git a/src/com/jogamp/opencl/demos/julia3d/UserSceneController.java b/src/com/jogamp/opencl/demos/julia3d/UserSceneController.java
index fda54be..17b8956 100644
--- a/src/com/jogamp/opencl/demos/julia3d/UserSceneController.java
+++ b/src/com/jogamp/opencl/demos/julia3d/UserSceneController.java
@@ -135,7 +135,7 @@ public class UserSceneController {
model.setEnableShadow(model.getEnableShadow()==0 ? 1 : 0);
break;
case '1':
- model.setEpsilon(model.getEpsilon() * 0.75f);
+ model.setEpsilon(max(0.0001f, model.getEpsilon() * 0.75f));
break;
case '2':
model.setEpsilon(model.getEpsilon() * 1.f / 0.75f);