1 package vtk.rendering.swt;
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.widgets.Composite;
5 import org.eclipse.swt.widgets.Event;
6 import org.eclipse.swt.widgets.Listener;
8 import com.jogamp.opengl.GLAutoDrawable;
9 import com.jogamp.opengl.GLCapabilities;
10 import com.jogamp.opengl.GLProfile;
11 import com.jogamp.opengl.GLRunnable;
12 import com.jogamp.opengl.swt.GLCanvas;
17 * @author Joachim Pouderoux - joachim.pouderoux@kitware.com, Kitware SAS 2012
18 * @copyright This work was supported by CEA/CESTA
19 * Commissariat a l'Energie Atomique et aux Energies Alternatives,
20 * 15 avenue des Sablieres, CS 60001, 33116 Le Barp, France.
22 public class vtkInternalSwtComponent extends GLCanvas implements Listener {
24 private vtkSwtComponent parent;
26 public static GLCapabilities GetGLCapabilities() {
28 caps = new GLCapabilities(GLProfile.get(GLProfile.GL2GL3));
29 caps.setDoubleBuffered(true);
30 caps.setHardwareAccelerated(true);
31 caps.setSampleBuffers(false);
32 caps.setNumSamples(4);
39 public vtkInternalSwtComponent(vtkSwtComponent parent, Composite parentComposite) {
41 super(parentComposite, SWT.NO_BACKGROUND, GetGLCapabilities(), null);
44 vtkSwtInteractorForwarderDecorator forwarder = (vtkSwtInteractorForwarderDecorator) this.parent
45 .getInteractorForwarder();
47 this.addMouseListener(forwarder);
48 this.addKeyListener(forwarder);
49 this.addMouseMoveListener(forwarder);
50 this.addMouseTrackListener(forwarder);
51 this.addMouseWheelListener(forwarder);
53 this.addListener(SWT.Paint, this);
54 this.addListener(SWT.Close, this);
55 this.addListener(SWT.Dispose, this);
56 this.addListener(SWT.Resize, this);
58 this.IntializeRenderWindow();
61 protected void IntializeRenderWindow() {
63 // setCurrent(); // need to be done so SetWindowIdFromCurrentContext can
64 // get the current context!
65 // Context is not created until the first draw call. The renderer isn't
66 // initialized until the context is
68 invoke(false, new GLRunnable() {
71 public boolean run(GLAutoDrawable arg0) {
72 // This makes this thread (should be the main thread) current
73 getContext().makeCurrent();
74 parent.getRenderWindow().InitializeFromCurrentContext();
75 // Swapping buffers is handled by the vtkSwtComponent
76 parent.getRenderWindow().SwapBuffersOff();
81 // Swap buffers to trigger context creation
83 setAutoSwapBufferMode(false);
87 public void update() {
95 public void dispose() {
96 this.removeListener(SWT.Paint, this);
97 this.removeListener(SWT.Close, this);
98 this.removeListener(SWT.Dispose, this);
99 this.removeListener(SWT.Resize, this);
101 if (getContext().isCurrent()) {
102 getContext().release();
108 public void handleEvent(Event event) {
109 switch (event.type) {
117 vtkObject.JAVA_OBJECT_MANAGER.gc(false);
120 // System.out.println("closing");
123 parent.setSize(getClientArea().width, getClientArea().height);