As i have written, i use jReality within an EclipseRCP application under native SWT. To get this working i have done several changes in the SWT classes already existing within the SVN repository.
One change that is necessary beyond the SWT implementation is the method within the JOGLRenderer class to set the rendering size:
Code: Select all
Index: src/de/jreality/jogl/JOGLRenderer.java
===================================================================
--- src/de/jreality/jogl/JOGLRenderer.java (revision 212)
+++ src/de/jreality/jogl/JOGLRenderer.java (working copy)
@@ -614,4 +614,9 @@
throw new IllegalArgumentException("Picking has been removed from JOGL renderer");
}
+ public void setSize(int width, int height) {
+ this.width = width;
+ this.height = height;
+ }
+
}
Code: Select all
Index: src/de/jreality/jogl/SwtQueue.java
===================================================================
--- src/de/jreality/jogl/SwtQueue.java (revision 212)
+++ src/de/jreality/jogl/SwtQueue.java (working copy)
@@ -63,16 +63,26 @@
}
private SwtQueue() {
- swtThread = new Thread(this);
- swtThread.start();
- synchronized(initLock) {
- try {
- while (!inited) initLock.wait();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ // check if we have already a display
+ Display disp = Display.getDefault();
+ if (disp != null) {
+ // display already existing
+ inited = false;
+ display = disp;
+ swtThread = disp.getThread();
+ }
+ else {
+ swtThread = new Thread(this);
+ swtThread.start();
+ synchronized(initLock) {
+ try {
+ while (!inited) initLock.wait();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
}
public Display getDisplay() {
@@ -90,7 +100,8 @@
shell[0].addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
shellCnt--;
- if (shellCnt==0) display.dispose();
+ // inited == false if the display was not constructed by this class
+ if (shellCnt==0 && inited) display.dispose();
}
});
};
Index: src/de/jreality/jogl/SwtViewer.java
===================================================================
--- src/de/jreality/jogl/SwtViewer.java (revision 212)
+++ src/de/jreality/jogl/SwtViewer.java (working copy)
@@ -228,8 +228,10 @@
int rot = 0;
public void init() {
+ canvas.setCurrent();
+
+ // track the size of the window
canvas.addListener(SWT.Resize, new Listener() {
-
public void handleEvent(Event event) {
Rectangle bounds = canvas.getBounds();
myDimension.width=bounds.width;
@@ -237,6 +239,15 @@
renderer.setSize(myDimension.width, myDimension.height);
}
});
+
+ // track update events
+ canvas.addListener(SWT.Paint, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ renderAsync();
+ }
+ });
+
context = GLDrawableFactory.getFactory().createExternalGLContext();
Rectangle bounds = canvas.getBounds();
myDimension.width=bounds.width;
Index: src/de/jreality/toolsystem/raw/DeviceMouseSWT.java
===================================================================
--- src/de/jreality/toolsystem/raw/DeviceMouseSWT.java (revision 212)
+++ src/de/jreality/toolsystem/raw/DeviceMouseSWT.java (working copy)
@@ -42,6 +42,7 @@
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
@@ -156,7 +157,7 @@
component.getDisplay().syncExec(r);
}
- public void initialize(Viewer viewer) {
+ public void initialize(Viewer viewer, Map<String,Object> config) {
if (!(viewer instanceof SwtViewer)) throw new RuntimeException("only for SWT viewer!");
setComponent(((SwtViewer)viewer).getGLCanvas());
}
Index: src/de/jreality/toolsystem/raw/DeviceKeyboardSWT.java
===================================================================
--- src/de/jreality/toolsystem/raw/DeviceKeyboardSWT.java (revision 212)
+++ src/de/jreality/toolsystem/raw/DeviceKeyboardSWT.java (working copy)
@@ -42,6 +42,7 @@
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
@@ -85,7 +86,7 @@
// maps InputDevices to Timers performing "keyReleased"
private HashMap pendingReleases=new HashMap();
- public void initialize(Viewer viewer) {
+ public void initialize(Viewer viewer, Map<String,Object> config) {
if (!(viewer instanceof SwtViewer)) throw new RuntimeException("only for SWT viewer!");
setComponent(((SwtViewer)viewer).getGLCanvas());
}