Commit 7edaedbb authored by Jensgw's avatar Jensgw

Include changes by ChrisB, rebase on vtk's master

parent b14b568c
Pipeline #121578 passed with stage
......@@ -50,22 +50,38 @@ endif()
set(JOGL_VERSION "2.3.2")
option(VTK_JAVA_JOGL_COMPONENT "Need JOGL jar files" OFF)
if(VTK_JAVA_JOGL_COMPONENT)
if(VTK_JAVA_JOGL_COMPONENT OR VTK_JAVA_SWT_COMPONENT )
set(MAVEN_REPO "$ENV{HOME}/.m2/repository")
find_file(JOGL_LIB jogl-all-${JOGL_VERSION}.jar PATHS ${MAVEN_REPO}/org/jogamp/jogl/jogl-all/${JOGL_VERSION} )
find_file(JOGL_GLUE gluegen-rt-${JOGL_VERSION}.jar PATHS ${MAVEN_REPO}/org/jogamp/gluegen/gluegen-rt/${JOGL_VERSION})
mark_as_advanced(JOGL_LIB JOGL_GLUE)
if(NOT JOGL_LIB)
message(ERROR "
CMake can not build VTK with VTK_JAVA_JOGL_COMPONENT ON if the JOGL jar file is not provided.
Please set the JOGL_LIB variable.
")
if(VTK_JAVA_JOGL_COMPONENT)
if(NOT JOGL_LIB)
message(ERROR "
CMake can not build VTK with VTK_JAVA_JOGL_COMPONENT ON if the JOGL jar file is not provided.
Please set the JOGL_LIB variable.
")
endif()
if(NOT JOGL_GLUE)
message(ERROR "
CMake can not build VTK with VTK_JAVA_JOGL_COMPONENT ON if the GLUE jar file is not provided.
Please set the JOGL_GLUE variable.
")
endif()
endif()
if(NOT JOGL_GLUE)
message(ERROR "
CMake can not build VTK with VTK_JAVA_JOGL_COMPONENT ON if the GLUE jar file is not provided.
Please set the JOGL_GLUE variable.
")
if(VTK_JAVA_SWT_COMPONENT)
if(NOT JOGL_LIB)
message(ERROR "
CMake can not build VTK with VTK_JAVA_SWT_COMPONENT ON if the JOGL jar file is not provided.
Please set the JOGL_LIB variable.
")
endif()
if(NOT JOGL_GLUE)
message(ERROR "
CMake can not build VTK with VTK_JAVA_SWT_COMPONENT ON if the GLUE jar file is not provided.
Please set the JOGL_GLUE variable.
")
endif()
endif()
endif()
......
......@@ -23,24 +23,24 @@ public class vtkInternalSwtComponent extends GLCanvas implements Listener {
private vtkSwtComponent parent;
public static GLCapabilities GetGLCapabilities() {
GLCapabilities caps;
caps = new GLCapabilities(GLProfile.get(GLProfile.GL2GL3));
caps.setDoubleBuffered(true);
caps.setHardwareAccelerated(true);
caps.setSampleBuffers(false);
caps.setNumSamples(4);
return caps;
}
public static GLCapabilities GetGLCapabilities() {
GLCapabilities caps;
caps = new GLCapabilities(GLProfile.get(GLProfile.GL2GL3));
caps.setDoubleBuffered(true);
caps.setHardwareAccelerated(true);
caps.setSampleBuffers(false);
caps.setNumSamples(4);
return caps;
}
public vtkInternalSwtComponent(vtkSwtComponent parent, Composite parentComposite) {
super(parentComposite, SWT.NO_BACKGROUND, GetGLCapabilities(), null);
this.parent = parent;
vtkSwtInteractorForwarderDecorator forwarder =
(vtkSwtInteractorForwarderDecorator)this.parent.getInteractorForwarder();
vtkSwtInteractorForwarderDecorator forwarder = (vtkSwtInteractorForwarderDecorator) this.parent
.getInteractorForwarder();
this.addMouseListener(forwarder);
this.addKeyListener(forwarder);
......@@ -58,62 +58,68 @@ public class vtkInternalSwtComponent extends GLCanvas implements Listener {
protected void IntializeRenderWindow() {
// setCurrent(); // need to be done so SetWindowIdFromCurrentContext can
// get the current context!
// Context is not created until the first draw call. The renderer isn't
// initialized until the context is
// present.
invoke(false, new GLRunnable() {
@Override
public boolean run(GLAutoDrawable arg0) {
// This makes this thread (should be the main thread current
// while the
getContext().makeCurrent();
System.out.println("Creating render Window");
parent.getRenderWindow().InitializeFromCurrentContext();
System.out.println("Done");
return false;
}
});
// Swap buffers to trigger context creation
swapBuffers();
setAutoSwapBufferMode(false);
}
@Override
public void update() {
super.update();
if (isRealized()) {
parent.Render();
}
}
@Override
public void dispose() {
getContext().release();
super.dispose();
}
@Override
public void handleEvent(Event event) {
switch (event.type) {
case SWT.Paint:
if (isRealized()) {
parent.Render();
}
break;
case SWT.Dispose:
parent.Delete();
vtkObject.JAVA_OBJECT_MANAGER.gc(false);
break;
case SWT.Close:
// System.out.println("closing");
break;
case SWT.Resize:
parent.setSize(getClientArea().width, getClientArea().height);
break;
}
}
// setCurrent(); // need to be done so SetWindowIdFromCurrentContext can
// get the current context!
// Context is not created until the first draw call. The renderer isn't
// initialized until the context is
// present.
invoke(false, new GLRunnable() {
@Override
public boolean run(GLAutoDrawable arg0) {
// This makes this thread (should be the main thread) current
getContext().makeCurrent();
parent.getRenderWindow().InitializeFromCurrentContext();
// Swapping buffers is handled by the vtkSwtComponent
parent.getRenderWindow().SwapBuffersOff();
return false;
}
});
// Swap buffers to trigger context creation
swapBuffers();
setAutoSwapBufferMode(false);
}
@Override
public void update() {
super.update();
if (isRealized()) {
parent.Render();
}
}
@Override
public void dispose() {
this.removeListener(SWT.Paint, this);
this.removeListener(SWT.Close, this);
this.removeListener(SWT.Dispose, this);
this.removeListener(SWT.Resize, this);
if (getContext().isCurrent()) {
getContext().release();
}
super.dispose();
}
@Override
public void handleEvent(Event event) {
switch (event.type) {
case SWT.Paint:
if (isRealized()) {
parent.Render();
}
break;
case SWT.Dispose:
parent.Delete();
vtkObject.JAVA_OBJECT_MANAGER.gc(false);
break;
case SWT.Close:
// System.out.println("closing");
break;
case SWT.Resize:
parent.setSize(getClientArea().width, getClientArea().height);
break;
}
}
}
......@@ -29,6 +29,9 @@ public class vtkSwtComponent extends vtkAbstractComponent<GLCanvas> {
this.eventForwarder = new vtkSwtInteractorForwarderDecorator(this, this.eventForwarder);
this.isWindowCreated = true;
this.uiComponent = new vtkInternalSwtComponent(this, parentComposite);
renderWindow.AddObserver("StartEvent", this, "startEvent");
renderWindow.AddObserver("EndEvent", this, "endEvent");
}
/**
......@@ -36,6 +39,7 @@ public class vtkSwtComponent extends vtkAbstractComponent<GLCanvas> {
* @param x width
* @param y height
*/
@Override
public void setSize(int x, int y) {
x = x < 1 ? 1 : x;
y = y < 1 ? 1 : y;
......@@ -49,6 +53,7 @@ public class vtkSwtComponent extends vtkAbstractComponent<GLCanvas> {
* Render the VTK component. Should not be called externally.
* Call update() to refresh the window content.
*/
@Override
public void Render() {
// Make sure we can render
if (inRenderCall || renderer == null || renderWindow == null) {
......@@ -81,10 +86,12 @@ public class vtkSwtComponent extends vtkAbstractComponent<GLCanvas> {
* @return the encapsulated SWT component (a GLCanvas instance)
* @see vtk.rendering.vtkAbstractComponent#getComponent()
*/
@Override
public GLCanvas getComponent() {
return this.uiComponent;
}
@Override
public void Delete() {
this.lock.lock();
// We prevent any further rendering
......@@ -110,4 +117,19 @@ public class vtkSwtComponent extends vtkAbstractComponent<GLCanvas> {
protected void updateInRenderCall(boolean value) {
this.inRenderCall = value;
}
/** This method is called by the VTK JNI code. Do not remove. */
void startEvent() {
if (!getComponent().getContext().isCurrent()) {
getComponent().getContext().makeCurrent();
}
}
/** This method is called by the VTK JNI code. Do not remove. */
void endEvent() {
if (getComponent().getContext().isCurrent()) {
getComponent().swapBuffers();
getComponent().getContext().release();
}
}
}
......@@ -27,7 +27,7 @@ public class SwtConeRendering {
public static void main(String[] args) {
Display display = new Display ();
Display display = new Display();
Shell shell = new Shell(display);
// build VTK Pipeline
......@@ -44,28 +44,29 @@ public class SwtConeRendering {
vtkSwtComponent swtWidget = new vtkSwtComponent(shell);
swtWidget.getRenderer().AddActor(coneActor);
shell.addControlListener(new ControlListener() {
shell.addControlListener(new ControlListener() {
@Override
public void controlResized(ControlEvent e) {
if (e.widget instanceof Shell) {
Shell s = (Shell) e.widget;
swtWidget.setSize(s.getClientArea().width, s.getClientArea().height);
}
}
@Override
public void controlResized(ControlEvent e) {
if (e.widget instanceof Shell) {
Shell s = (Shell) e.widget;
swtWidget.setSize(s.getClientArea().width, s.getClientArea().height);
}
}
@Override
public void controlMoved(ControlEvent e) {
// TODO Auto-generated method stub
@Override
public void controlMoved(ControlEvent e) {
// TODO Auto-generated method stub
}
});
}
});
shell.pack();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose ();
display.dispose();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment